Skip to Content

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

To report this post you need to login first.

17 Comments

You must be Logged on to comment or reply to a post.

  1. Faaiez Sallie
    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

    (0) 
    1. Faaiez Sallie
      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

      (0) 
  2. 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

    (0) 
    1. 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.

      (0) 
      1. 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 ?
         
        (0) 
      2. 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?
        (0) 
      3. 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?
        (0) 
        1. 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.

          (0) 
  3. Nils Vanderheyden
    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.

    (0) 
      1. Nils Vanderheyden
        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

        (0) 
        1. Thomas Alexander Ritter 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

          (0) 
          1. Nils Vanderheyden
            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

            (0) 

Leave a Reply