新会话开始时保存全局属性值 [英] Save global attribute value when new session starts

查看:24
本文介绍了新会话开始时保存全局属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SAP Fiori 应用中有两个字段:Template_IDOffer_ID.

I have two fields in SAP Fiori App: Template_ID and Offer_ID.

我想根据 Template_ID 字段值选择 Offer_ID 中的值.

I want to choose value in Offer_ID depending on Template_ID field value.

为了解决这个问题,我尝试执行以下步骤:

For solving this problem I've tried to do this steps:

当用户点击 Back-End 中的 Template_ID 字段时运行该方法:

When the user click on Template_ID field in Back-End runs the method:

CL_CUAN_CAMPAIGN_DPC->contentset_get_entityset().

这个方法有返回参数et_result.在 et_result 中,我有必要的字段 temp_id.

This method has returning paramater et_result. In et_result I have the necessary field temp_id.

为了保存 temp_id 值,我在 ZCL_CUAN_CLASS 类中创建了一个全局属性.

For saving temp_id value I created a global attribute in class ZCL_CUAN_CLASS.

ZCL_CUAN_CLASS=>GV_CONTENT = VALUE #( et_result[ 1 ]-temp_ID OPTIONAL ).

我将使用这个全局属性作为我的第二种方法的 input 参数:

I'll use this global attribute as an input parameter for my second method:

CL_CUAN_CAMPAIGN_DPC->GET_OFFER_BY_TEMPLATE().

此方法将带有offer_id 的内部表返回给我,该表属于我选择的temp_id.

This method returns to me the internal table with the offer_id, which belongs to my choosen temp_id.

但是当用户单击 Web UI 上的 Offer_ID 字段时,在调试中我看到我的全局属性为空.

But when the user click on Offer_ID field on Web UI, in debugging I see that my global attribute is blank.

可能是因为会话或其他原因,但它是空白的.

May be it's because of session or something else, but it's blank.

推荐答案

OData 是一种无状态协议,这意味着服务器响应您的查询,然后忘记您曾经在那里.根据定义,这不允许您将主内存内容从一个请求传输到下一个请求.

OData is a stateless protocol, meaning the server responds your query, then forgets you were ever there. By definition, this does not allow you to transport main memory content from one request to the next.

另一方面,用户界面通常需要状态.它可以通过以下选项之一获得:

User interfaces on the other hand usually require state. It can be gained through one of the following options:

正如 Haojie 所指出的,一种解决方案是存储在用户界面中选择的数据,并在下一个请求时将其作为过滤条件提交回服务器.有状态的用户界面是无状态服务器应用的标准解决方案.

As Haojie points out, one solution is to store the data that was selected in the user interface and submit it as a filter criterion back to the server with the next request. Having a stateful user interface is the standard solution for stateless server apps.

另一种选择是将数据永久存储在服务器的数据库中,最好在 ABAP 中存储在业务对象中.此对象具有唯一标识符,可能是 GUID,您可以在请求中引用该标识符来标识您正在处理的流程.

Another option is to store the data permanently in the server's database, in ABAP preferredly in a business object. This object has a unique identifier, probably a GUID, that you can reference in your requests to identify the process you are working on.

如果在一个步骤中并非所有信息都可用,例如在多步骤向导中,则不应立即激活",或者您希望能够在处理多步骤过程时切换设备,草稿是一种选择.草稿是常规业务对象,其一个特点是在用户触发最终激活步骤之前它们保持惰性.

If not all information is available in one step, such as in a multi-step wizard, should not become "active" right away, or you want to be able to switch devices while working on a multi-step process, drafts are an option. Drafts are regular business objects, with the one specialty that they remain inert until the user triggers a final activation step.

关于性能优化,你可以看看SAP Gateway 的软状态模式,可以让你缓存一些数据,以便能够更快地响应相关请求.不过,这通常是不鼓励的,因为它与 OData 的无状态范式相矛盾.

For performance optimizations, you can have a look at SAP Gateway's soft state mode, which allows you to buffer some data to be able to respond to related requests more quickly. This is generally discouraged though, as it contradicts the stateless paradigm of OData.

在某些情况下,像 OData 这样的无状态协议不是正确的方法.例如,银行应用程序仍然更喜欢关联状态,以避免用户无限登录,从而容易受到 CSRF 等攻击.如果是这种情况,您应该查看 ABAP WebDynpro 的用户界面.一般来说,有状态的服务器协议被认为是次等的,因为它们长时间绑定了大量的服务器资源,因此无法处理更大的用户数量.

In some cases, stateless protocols like OData are not the right way to go. For example, banking apps still prefer to pertain state to avoid that users remain logged in infinitely, and thus becoming vulnerable to attacks like CSRF. If this is the case for you, you should have a look at ABAP WebDynpro for your user interface. Generally, stateful server protocols are considered inferior because they bind lots of server resources for long times and thus cannot handle larger user numbers.

这篇关于新会话开始时保存全局属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆