BSP: Stateless Modelbinding – Proof Of Concept
h2. Introduction
Last year there were some questions in the forum regarding stateless modelbinding check out the thread Data Binding for Sateless Applications. I liked the ideas which were presented in this thread but wasn’t sure how they will work. So I took some time and built a small proof of concept application. It should be a good start for all people who want a bigger challenge and go stateless 😉
What you are going to learn:
- How to use modelbinding
- How to use serialization
- How to create and read server cookies
The application
At first lets take a look what the application looks like:
I would store the whole store/restore logic into a separate class so that I can use it for more than one application. It would also allows you to easily modify how and where the serialized data is stored (in a browser cookie, in a server cookie, in a new table,…) since the application itself would not be affected. The DataMapper pattern from Martin Fowler is a good example how it can be done: Data Mapper Pattern
Related Weblogs:
ABAP Serialization – Part I: Quick-n-easy
- [The unfortunate cookie | The unfortunate cookie]
BSP In-Depth: Confusion between Stateless, Stateful and Authentication
- [How to create your first OO Abap Class for a BSP | How to create your first OO Abap Class for a BSP]
iStream however contains the same data as oStream did in the StoreModel method. Any assistance in this regard would be appreciated.
Thanks again.
Faaiez
Thanks again
Faaiez
No problem 🙂
I am glad you found the problem so it works, now?
regards
Thomas
i tried example it worked fine,
but for other application i am getting the problem in storemodel( ) method while callin g
transformation staement ( Serialization error ). i implemented the IF_SERIALIZABLE_OBJECT interface.
ofcourse my model class is big one it contained huge data ( 4 internal tables ). is it will cause any problem while transfer model to xml string.
Plese help me
I have serialized some rather large classes before. I had one program that created a 20Meg XML file. Now this wasn't in the context of BSP MVC although that really shouldn't matter to the transformation call.
thanks for your response
my class has some reference variables for example type ref to data and some others,
I put the reference varaible in your example also there aslo i got the error.
does we transform the class even if the class contain some references ?
thanks for your response
Actually my class contains some referenc variables
like type ref to data and some other references .
i put the references in your example and tried there also i got the error.
does we transform the class into xml even if it contains references?
thanks for your response
Actually my class contains some referenc variables
like type ref to data and some other references .
i put the references in your example and tried there also i got the error.
does we transform the class into xml even if it contains references?
A TYPE REF TO DATA however I don't think would work. With a generic data reference, how would the system know what XML type to create? You might read the online help for CALL TRANSFORMATION. In 640 there are some helper methods that you can program, but even with these I don't know if this would be possible.
Is there a way to data within the standaard CL_BSP_MODEL which you inherent in your model class?
I think data is lost here beceause CL_BSP_MODEL doesn't use the IF_SERIALIZABLE_OBJECT interface.
Own defined data is working fine.
you are right. You can only serialize objects if they implement the tagging interface if_serializable_object.
cheers
Thomas
If you use controller and modell classes then the model reference also will be destroyed after user action - resulting in the failure of the dispatch_input. (subcontroller needs the CL_BSP_MODEL-owner reference to be filled).
Did you have a solution for this? I don't like to enhance the standard SAP class "CL_BSP_MODEL" with the if_serializable_object interface.
Thanks in advance.
Cheers,
Nils
I am not sure what you mean by "user action". Do you mean pressing a button, etc.? The example application works when clicking the "update" button.
I have to admit that I have not written anything BSP-related during the last 6 years so I can only give you some ideas.
Did you try overwriting the dispatch_input method similarly to how I overwrote the do_handle_data method?
method dispatch_input.
me->model ?= me->restoreModel( ).
super->dispatch_input( ).
endmethod.
cheers
Thomas
With "user action" i do mean a click on a button. Event is triggerd.
Looks like the following line solved my problem.
me->model->IF_BSP_MODEL~INIT( id = 'mod' owner = me ).
Cheers
good to hear that you could solve the problem!
cheers
Thomas