cancel
Showing results for 
Search instead for 
Did you mean: 

Adaptive Web Service call in WD

Former Member
0 Kudos

Hi experts,

I am new to WebDynpro Java (used in CE 7.2).

I am calling a web service for getting data for an employee in our ERP backend in the WDdoInit() of the Component Controller.

That works and the result is shown on the screen.

Now I have the problem to write the results back to the context of my Component Controller.

The Component Controller's context looks like the following:

|-<b>Context</b>

|---<b>Requestor</b>

|-----FirstName

|-----LastName

|---<b>Reqeuest_ZHR_GET_EMPLOYEE</b>

|-----<b>Response</b>

|-------<b>ZHR_GET_EMPLOYEE_Response</b>

|----


E_NACHN

|----


E_VORNA

|-------<b>ZHR_GET_EMPLOYEE</b>

|----


I_UNAME

After calling the WS I display the values of the attributes "E_NACHN" and "E_VORNA" on the screen.

Now I want to copy those values to the attributes "FirstName" and "LastName" under node "Requestor" in my Component Controller context.

I've tried the following in wdDoInit(), but it doesn't work:


WSModel model = new WSModel();
Request_ZHR_GET_EMPLOYEE request = new Request_ZHR_GET_EMPLOYEE(model);
	
ZHR_GET_EMPLOYEE requestor = new ZHR_GET_EMPLOYEE(model);
requestor.setI_UNAME(userID);
request.setZHR_GET_EMPLOYEE(requestor); 
	
wdContext.nodeRequest_ZHR_GET_EMPLOYEE().bind(request);
	
//$$begin Service Controller(-1569958994)
initRequest_ZHR_GET_EMPLOYEE();
//$$end
executeZHR_GET_EMPLOYEE();

Response_ZHR_GET_EMPLOYEE response = request.getResponse();
    
String vorna = response.getZHR_GET_EMPLOYEEResponse().getE_VORNA();
String nachn = response.getZHR_GET_EMPLOYEEResponse().getE_NACHN();

wdContext.nodeRequestor().currentRequestorElement().setFirstName(vorna);
wdContext.nodeRequestor().currentRequestorElement().setLastName(nachn);

Why are the values afterwards not in the context of my Component Controller?

The variables "vorna" and "nachn" are holding the correct values...

Thanks in advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

Qualiture
Active Contributor
0 Kudos

Hi,

Have you checked the cardinality of the Requestor value node?

Cardinality should be 1..1 to ensure only a single element in the 'list'.

And you can simplify your setters to the following:

wdContext.currentRequestorElement().setFirstName(vorna);
wdContext.currentRequestorElement().setLastName(nachn);

If you are sure variables 'vorna' and 'nachn' are actually filled correctly, the approach above should work

Best regards,

Robin van het Hof

Edited by: R. van het Hof on Mar 24, 2011 2:35 PM

Fixed typo

Former Member
0 Kudos

I solved it myself.

I assigned the values in an action method of the View:

public void onActionFillleaverequestTaskCompleteEvent(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionFillleaverequestTaskCompleteEvent(ServerEvent)
	String LastName        = 
		wdContext.currentZHR_GET_REQUESTORResponseElement().getE_NACHN();
	String FirstName       = 
		wdContext.currentZHR_GET_REQUESTORResponseElement().getE_VORNA();
	  
	wdContext.currentRequestorElement().setLastName(LastName);
	wdContext.currentRequestorElement().setFirstName(FirstName);
	  
    wdThis.wdGetFillleaverequestTaskComponentController().fireFillleaverequestTaskCompleteEvent();
    //@@end
  }

But I still don't understand why it didn't work before in wdDoInit() of the component controller.

Can anybody explain me that?

Qualiture
Active Contributor
0 Kudos

Hi Eddie,

I'm not sure why it didn't work in the wdDoInit() method, setting context values should work here just as fine as in an action handler.

The only reason it wouldn't work that I can think of, is if during initializing of the view the variables aren't properly set.

Bear in mind, the wdDoInit() method is called only once in the application's lifetime, so if you expect the view to call this method again after a user action (filling in form fields, clicking a button, etc) this method won't be called.

Better indeed is make use of action handlers like you did, or (for changes to the view) the wdDoModifyView method.

Hope this explains a bit!

Best regards,

Robin van het Hof

Former Member
0 Kudos

Come on, that's really a beginner's question

I've now tried a lot, but it doesn't work.

How can I map my model nodes with the value nodes of the Compont controller's context???