问题
I have two fields in SAP Fiori App: Template_ID
and 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:
When the user click on Template_ID
field in Back-End runs the method:
CL_CUAN_CAMPAIGN_DPC->contentset_get_entityset()
.
This method has returning paramater et_result
. In et_result
I have the necessary field temp_id
.
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 ).
I'll use this global attribute as an input
parameter for my second method:
CL_CUAN_CAMPAIGN_DPC->GET_OFFER_BY_TEMPLATE()
.
This method returns to me the internal table with the offer_id
, which belongs to my choosen temp_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.
回答1:
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:
Stateful user interface
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.
Stateful persistence
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.
Draft persistence
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.
Soft state
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.
Stateful protocol
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.
回答2:
When ther user click on OfferId field, it will start a NEW session and of course what you store as GV_CONTENT
in class ZCL_CUAN_CLASS
is lost.
What you should do is that for the second request you should send to backend with filter Template_ID
so in your CL_CUAN_CAMPAIGN_DPC->GET_OFFER_BY_TEMPLATE()
method, you can further process the result by Template_ID
.
Or SET/GET Parameter.
来源:https://stackoverflow.com/questions/58102499/save-global-attribute-value-when-new-session-starts