cancel
Showing results for 
Search instead for 
Did you mean: 

Adaptive WebService and 1:n relation in the response

Former Member
0 Kudos

For an adaptive WebService the model must be instantiated manually.

This is described for 1:1 relations between model nodes, but what's about 1:n?

The root node of a 1:n relation has a setIXXX(List list) method, so in wdDoInit() i can call it with root.setXXX(new ArrayList());

But how do I have to instantiate the childs?

TIA

Thomas Paulsen

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Thomas,

If you have any child nodes then you have to find the corresponding structure/table associated with your child node and then you have to instantiate the child nodes in the following way.

You can write the below code in the wdDoInit() of component controller.

public void wdDoInit()

{

//@@begin wdDoInit()

// Create a new element in the Bapi_Flight_Getlist_Input node

Bapi_Flight_Getlist_Input input = new Bapi_Flight_Getlist_Input();

wdContext.nodeBapi_Flight_Getlist_Input().bind(input);

// Create new elements in the Destination_From and Destination_To nodes

input.set<Destination_From>(new Bapisfldst());

input.set<Destination_To>(new Bapisfldst());

//Here <b>Bapisfldst </b>is a structure in R/3.

//If it a table then you need to use add instead of set.

ZTest_tab tab = new ZTest_tab();

input.add<MyTab>(tab );

//@@end

}

Regards,

Jhansi

Former Member
0 Kudos

Hi, Jhansi

Sorry, a little bit late, but vacation and easter and a hdd crash (aarrrgghh)....

I'd found the input.add<tab>.(new tabElement(model)) method, and it works fine for inputs, because I know the number of elements and I can use it in wdDoInit() or any other method during the preprocessing of the call.

But how to handle the output of a call if it returns a list of elements?

Regards,

Thomas

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

bind a Table UI element to this multiple node. Its node elements will be displayed as table lines.

Regards, Bertram

Former Member
0 Kudos

Hi Bertram

I know how to bind a table UI element to the context node, I don't know how to bind one to the model.

After binding a table UI element to the context node and processing the call the table is empty.

I think because I have no model nodes because I don't know where and how to create the model nodes

Regards

Thomas

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

look at my newest in-depth tutorial and article on using the <b>Adaptive Web Service Model</b>

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/301ff0bb-74ca-2910-fa99-eae392695aad">Creating an E-Mail Client Using Web Dynpro's Adaptive Web Service Model</a>

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/900bbf94-a7a8-2910-e298-a651b4706c1e">WDJ Adaptive Web Service Model – Controller Coding Explained</a>

I will roll out this new material very soon. You can allready access it.

Regards, Bertram

Former Member
0 Kudos

Hi,

Thanks for the fast reply.

The 2nd document seems to be very helpful.

Seems my error was that I try to create the response nodes manually. I have to figure it out in detail.

I'll tell you the results on monday

Regards

Thomas

Former Member
0 Kudos

Hi Bertram,

I'd followed the 2nd tutorial step by step.

The "Variables" window of the debugger shows that calling the wdcontext.nodeResponse().invalidate() creates a node "Response" in the childs list of the request node.

But there are differences between the "Response" and the "SendMail" nodes

- the "parentElement" property is empty/null (!!!). In my opinion It should refer to the request element too.

- the "elements" property is empty (null)

- the "children" property is empty (null)

In my case the response should return a structure, so the "children" property should be non-empty.

The same request works fine when using non-adaptive WebService, so there must be something wrong when I'm using the adaptive WebService model.

Regards

Thomas

Message was edited by:

Thomas Paulsen

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

could you please specify the context structure bound to the Adaptive WS model classes. Having this context structure it is much easier for me to find a solution.

Regards, Bertram

Former Member
0 Kudos

Hi Bertram

The structure:

request

- requestIn

- requestIn - Attrib1

- requestIn - Attrib2

- requestIn - Attrib3

- requestIn - Attrib4

- response

- response - Out

- response - Out - ListName

- response - Out - ListName - Elements [0...n]

- response - Out - ListName - Elements - Attrib1

- response - Out - ListName - Elements - Attrib2

Regards

Thomas

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

and your controller coding in wdDoInit() and in the execute()/onSomeActionEvent() method?

Regards, Bertram

Former Member
0 Kudos

Hi Bertram,

the methods:


public void wdDoInit()
  {
    MyModel model = new MyModel();
   
    TWdProcessIn tWdProcessIn = new TWdProcessIn(model);
    WdRequest request = new WdRequest(model);

    request.setWdProcessIn(tWdProcessIn);
	
    wdContext.nodeRequest().bind(request);
  }

  public void executeRequest( )
  {
	IWDMessageManager manager = wdComponentAPI.getMessageManager();
	try
	{
		wdContext.currentRequestElement().modelObject().execute();
		wdContext.nodeResponse().invalidate();
	} catch(Exception ce) {
		manager.reportException(ce.getMessage(), false);
	}
   }

Regards

Thomas<i></i><i></i>

Former Member
0 Kudos

I have had similar issue and what i do is copy the model nnode to context node and bind that to the table.

Also u have to instantiate all model nodes(request and response) which are sub nodes i mean level 2 or 3.

Message was edited by:

vasuki lm

Former Member
0 Kudos

Hi Vasuki

Bertrams tutorial says: The response objects will be created and referenced automatically, you only have to call the invalidate() method.

I'd tried creating the response model nodes manually. But there's a 0..n relation, I don't know how to handle this.

Regards

Thomas

Former Member
0 Kudos

Exactly my point.

You need to create the elements and assign dummy values.

Let me give you a example.Lets says your model response class is called

ResponseABC.

, then in you init or wherever before webservice call ,

Request_MAINSERVICE rserv = new Request_MAINSERVICE(model);

COMPLEX_TYPE_TOPELEVELMODEL top = new COMPLEX_TYPE_TOPELEVELMODEL;

rserv.setXXX(top);

ResponseABC rabc = new ResponseABC();

top.getOriginalBean().setYYY(rabc);

wdContext.node<NameoftoplevelnodeinVIEW>.bind(rserv);

This way even though cardinality is zero , u create one element and thus u wont get the error.

This is the basic idea , hope you figure it out.

HOPE SAP understands that a lot of times we use external web services and hence really in no position to control the cardinality and thus do something to make it easier for us.Either that or let us know if there really is someother easier way.

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Vasuki,

you refer to the former Web Service Model (.getOriginalBean()). Do not mix up workarounds here among the different Web Service model flavors. Adding a dummy object instance to the model node Return is not needed. The Web Dynpro Runtime will automatically set a reference to the response object in the model object graph.

Regards, Bertram

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

does the Web Service really return data? To find this out easily do the following steps:

1) Add a TextEdit UI Element to you View Layout and set Rows=20

2) Bind it to a context attribute RequestTrace of type string

3) After executing your adaptive Web Service object invoke

requestMO.execute();
wdContext.currentContextElement().setRequestTrace(requestMO.toString());

4) Start your application and have a look at the response of your Web Service. Does it really return data?

Regards, Bertram

Former Member
0 Kudos

Hi Bertram Ganz /Thomas ,

Sorry in that case then.I guessed the same way would work for instantiating in both cases.But i would imagine still that the idea remains the same.

Good luck Thomas

PS : Bertram Ganz : Maybe a bit out of topic , Would you have any idea from which release adaptive model will support external web services ? Thanks for any info.

Message was edited by:

vasuki lm

Former Member
0 Kudos

Hi Bertram

5 items in the list:

...

<target roleName="Response">

<modelObject class="Response_WdSearchWorkspace">

<target roleName="WdSearchWorkspace_Out">

<modelObject class="TWdSearchWorkspaceProcessOut">

<target roleName="Workspaces">

<modelObject class="Workspaces">

<targets roleName="Item">

<modelObject class="Item">

<attribute name="Name" value="name 1"/>

<attribute name="Id" value="68"/>

</modelObject>

<modelObject class="Item">

<attribute name="Name" value="name 2"/>

<attribute name="Id" value="67"/>

</modelObject>

<modelObject class="Item">

<attribute name="Name" value="name 3 "/>

<attribute name="Id" value="69"/>

</modelObject>

<modelObject class="Item">

<attribute name="Name" value="name 4"/>

<attribute name="Id" value="70"/>

</modelObject>

<modelObject class="Item">

<attribute name="Name" value="name 5"/>

<attribute name="Id" value="71"/>

</modelObject>

</targets>

</modelObject>

</target>

</modelObject>

</target></modelObject></target>

Former Member
0 Kudos

BTW:

NW04s/SPS11

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Thomas,

this is strange: Your Web Service returns data but it is not transported to the client. Did you really bind the table to the model node Response - Out - ListName - <b>Elements</b>, and the cell editors to the underlying attributes?

Regards, Bertram

Former Member
0 Kudos

Hi Bertram,

The first thing I'd figured out:

The "supplyingRelationRole" for "Worksapce" was missing.

After setting it to "Item", the Table UI element shows one line.

Only the very first, not all five.

Regards

Thomas

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

Hi Thomas,

Do you have addXXX(XXX xxx) method for your model?

Best regards, Maksim Rashchynski.