Skip to Content
Author's profile photo Thomas Alexander Ritter

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

BSP In-Depth: Confusion between Stateless, Stateful and Authentication

Assigned Tags

      17 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Thomas Jung
      Thomas Jung
      This is a very nice explaination of what could have been a very complex topic.  Good Job!
      Author's profile photo Former Member
      Former Member
      Thanks Thomas and don't forget Brain and you were the ones who initiated the creation of this weblog 🙂
      Author's profile photo Former Member
      Former Member
      I would like to thank you for this proof of concept. I have implemented this as a test in our WAS 6.20 SP 42 Kernel Patch 1800. There however seems to be a problem with the deserialization as when the call transformation intruction is processed the model is not filled.
      iStream however contains the same data as oStream did in the StoreModel method. Any assistance in this regard would be appreciated.

      Thanks again.

      Faaiez

      Author's profile photo Former Member
      Former Member
      What an idiot !!! 🙂 Sorry about this. Immediately after I posted the message I realised a very important thing I did not do. I did not add the IF_SERIALIZABLE_OBJECT interface to my model.

      Thanks again

      Faaiez

      Author's profile photo Former Member
      Former Member
      Hi Faaiez

      No problem 🙂
      I am glad you found the problem so it works, now?

      regards

      Thomas

      Author's profile photo Former Member
      Former Member
      Hi 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

      Author's profile photo Thomas Jung
      Thomas Jung
      Can you provide more details on the serialization error?  You should be able to catch that error into an exception class.  That should give you more to go on as to the cause of the serialization error. 

      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.

      Author's profile photo Former Member
      Former Member
      Hi thomas
        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 ?
       
      Author's profile photo Former Member
      Former Member
      Hi thomas
      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?
      Author's profile photo Former Member
      Former Member
      Hi thomas
      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?
      Author's profile photo Thomas Jung
      Thomas Jung
      You can serialize references if the class that it referes to also implements the IF_SERIALIZABLE_OBJECT interface. 

      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.

      Author's profile photo Former Member
      Former Member
      First of all thanks for a great Blog.

      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.

      Author's profile photo Thomas Alexander Ritter
      Thomas Alexander Ritter
      Blog Post Author
      Hi Nils,

      you are right. You can only serialize objects if they implement the tagging interface if_serializable_object.

      cheers
      Thomas

      Author's profile photo Former Member
      Former Member
      Hi 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

      Author's profile photo Thomas Alexander Ritter
      Thomas Alexander Ritter
      Blog Post Author
      Hi 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

      Author's profile photo Former Member
      Former Member
      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

      Author's profile photo Thomas Alexander Ritter
      Thomas Alexander Ritter
      Blog Post Author
      Hi Nils,

      good to hear that you could solve the problem!

      cheers
      Thomas