Skip to Content
avatar image
Former Member

How to implement Getter-Setter-Pattern with context-model binding

Hello *,

suppose I have a web service (or any other compatible data source) with a getter and setter method for a simple string value.

How would I design the context and bind it to the model?

What are the general steps to retrieve the string from the model and write it back (e.g. after it has been changed by the user)?

Is a different approach necessary for multi-row data (i.e. a table)?

I'm a bit confused from the examples since there is only a single execute method and a 1-to-1 relationsship from context node/value to a model function.

Thanks for any help!

Regards

Martin

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    May 26, 2004 at 08:56 AM

    Hi Martin,

    This would be content for a two hour hands-on workshop at TechEd 😊

    I would say, start with the Model and bind the controller context. Please take the email web service tutorial - this one should be the right one to start with.

    If you have further questions, let me know!

    Best regards,

    Karin

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 26, 2004 at 09:19 AM

    Karin,

    I can imagine that a comprehensive answer would be very long indeed.

    Unfortunately, the examples and docs I've found so far (including the email example) couldn't solve my question.

    In the email example the communication is one-way (data is written to the model but not retrieved from it).

    Is there any further documentatione/example/forum-thread on the fundamental steps "get data from model" - "manipulate it" - "write it back to model"?

    Maybe I'm stuck here with my Java background of getter and setter methods, but how then is the WD approach to these basic steps?

    Just a few hints would be very, very helpful.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Martin,

      you have to look at it a little bit more coarse-grained. Assuming you have an EJB with a "getData" and a "writeBack" business method the WD model creation will result in one WD model for the Web Service (if both methods are exposed in the WS of course) with two different "Request"- and "Response/Result"-model classes.

      Getting data is one execute() call using the Request-model of getData, writing back is one execute() call using Request_writeBack modelclass.

      The method parameters of each business method are the model-class attributes and, if bound to a context the model context node attributes you can set before the call. The return values of the business methods (if there are any) will be transferred to the Result_getData and Result_writeBack nodes respectively.

      Hope that helps.

      Regards

      Stefan

  • avatar image
    Former Member
    May 26, 2004 at 12:01 PM

    Hello Stefan,

    many thanx for your reply.

    So the bottom line is, if I have 2 different methods in my web service to get and to set the data, I must eventually copy data in the context. This is because context nodes / values can only be bound to a single model method.

    Hope I've got it right now. Or are there any alternatives?

    Regards

    Martin

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Martin,

      yes, that's right. But you can use the value objects pattern to transfer the data. Assume you have a simple value object representing a person (PersonVO) and the result from the getData-businessmethod is a PersonVO, you can change this object and pass it as the input of the writeBack-model request:

      wdContext
        .currentRequest_WSSimpleWebViDocument_setPersonElement()
        .modelObject()
        .setPerson(wdContext.currentResultElement().modelObject());

      The good news are that, despite the fact, you are using a plain old java object for this, since the Web Service creation transposes the class into a complex "SOAP object" the attributes (getters and setters) of the Java class are available as <b>bindable context attributes</b>. So, mapping model nodes from a view controller to the controller context handling the Web Service, you can use these attributes for UI elements.

      Hope that helps.

      Regards

      Stefan