cancel
Showing results for 
Search instead for 
Did you mean: 

Array node not being sent to web service

darren_hague
Contributor
0 Kudos

Hi All,

I have a Web Dynpro app which is successfully calling several methods on a Session EJB using web services.

The one problem I have is calling a method which takes a String and an "array of long" as parameters. When I debug the EJB, the String parameter comes through OK, but the array comes through as length zero instead of containing elements.

I'm setting the context node up as follows:


Request_TechBusRoleViDocument_mapUserToBusinessRoles mapUserToBusinessRoles = 
        new Request_TechBusRoleViDocument_mapUserToBusinessRoles();
wdContext.nodeMapUserToBusinessRoles().bind(mapUserToBusinessRoles);

IMapBusRoleidNode rolesToAssign = wdContext.nodeMapBusRoleid();
	
IMapBusRoleidElement roleToAssign1 = 
         wdContext.nodeMapBusRoleid().createMapBusRoleidElement(new Array_long());
			
IMapBusRoleidElement roleToAssign2 = 
         wdContext.nodeMapBusRoleid().createMapBusRoleidElement(new Array_long());
			
roleToAssign1.setValue(1L);
roleToAssign2.setValue(2L);
			
wdContext.currentMapUserToBusinessRolesElement()
        .setUserId(wdContext.currentFindBusRolesForUserElement().getUserId());
wdContext.currentMapUserToBusinessRolesElement()
        .modelObject().execute();

The context structure is:


mapUserToBusinessRoles
 +-mapBusRoleid
 | +-value
 +-userId

So mapBusRoleId is an array of value (which is a long), and userId is a String.

I don't have any problems with methods which return a long[], the only problem is with this one method which is trying to send a long[] as a parameter.

Anyone have an idea why it doesn't work, or how to fix it?

Cheers,

Darren

Message was edited by: Darren Hague

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Darren,

First find out the structure associated with the node "<b><i>mapBusRoleid</i></b>".

mapUserToBusinessRoles.addmapBusRoleid(<b>X</b>);

i.e,. find out what is the argument that the above line of code expects.

Once you know <b>X</b>, you may add the following lines of code:


Request_TechBusRoleViDocument_mapUserToBusinessRoles mapUserToBusinessRoles = 
        new Request_TechBusRoleViDocument_mapUserToBusinessRoles();
wdContext.nodeMapUserToBusinessRoles().bind(mapUserToBusinessRoles);

X x1 = new X();
x1.setValue(1);
mapUserToBusinessRoles.addmapBusRoleid(x1);

X x2 = new X();
x2.setValue(2);
mapUserToBusinessRoles.addmapBusRoleid(x2);

wdContext.currentMapUserToBusinessRolesElement()
        .setUserId(wdContext.currentFindBusRolesForUserElement().getUserId());
wdContext.currentMapUserToBusinessRolesElement()
        .modelObject().execute();

Bala

Former Member
0 Kudos

Bala,

You're right in that my sample code omitted an "add" call for the node - my mistake in cutting down my original code, but even with an "add" in place, the array doesn't get passed through.

Where you have

X x1 = new X();

I believe this is equivalent to my

IMapBusRoleidElement roleToAssign1 = 
         wdContext.nodeMapBusRoleid().createMapBusRoleidElement(new Array_long());

- the createMapBusRoleidElement creates a new element of the correct type.

wdContext.nodeMapUserToBusinessRoles() only has two methods beginning with <b>add</b>, and they both take a generic IWDNodeElement structure, which doesn't help too much.

My actual (more complex) code is this (I'm copying some values from an existing node fbrfuResult to the node for the web service call, mapUserToBusinessRoles):


IFbrfuResultNode assignedRoles = wdContext.nodeFbrfuResponse().nodeFbrfuResult();
IMapBusRoleidNode rolesToAssign = wdContext.nodeMapBusRoleid();
	
int numAssignedRoles = assignedRoles.size();
for (int i = 0; i < numAssignedRoles; i++) {
	IFbrfuResultElement role = assignedRoles.getFbrfuResultElementAt(i);
	IMapBusRoleidElement roleToAssign =
		wdContext.nodeMapBusRoleid().createMapBusRoleidElement(new Array_long());
	roleToAssign.setValue(role.getId());
	rolesToAssign.addElement(roleToAssign);
	msgMgr.reportSuccess("Added role "+role.getName()+" for user");
}
msgMgr.reportSuccess("Adding "+wdContext.nodeMapBusRoleid().size()+" roles");
wdContext.currentMapUserToBusinessRolesElement().setUserId(wdContext.currentFindBusRolesForUserElement().getUserId());
wdContext.currentMapUserToBusinessRolesElement().modelObject().execute();

When I run the code, the msgMgr calls show that the elements appear to be added to the node correctly, they just don't show up when the EJB gets called.

- Darren

Former Member
0 Kudos

Hello Darren,

<i>wdContext.nodeMapUserToBusinessRoles() only has two methods beginning with add, and they

both take a generic IWDNodeElement structure, which doesn't help too much.</i>

You are trying to add an element to the nodeMapUserToBusinessRoles(), whereas the code that I had

posted in my previous reply tries to add the corresponding structure to the modelObject associated with the current node instance (element).There is a difference between these two.

If you carefully walk though my earlier reply you will find that

mapUserToBusinessRoles.addmapBusRoleid(x1);

is equivalent to

wdContext.currentMapUserToBusinessRolesElement()
        <b>.modelObject().addmapBusRoleid(x1);</b>

and NOT the addition of element to a node.

You may find out the structure associated with the node mapBusRoleid through these steps:

1) Goto the context tab of the view/CC whereever you have this node mapBusRoleid.

2) Right Click the node mapBusRoleid and select properties.

3) Look for a property called "Structure" and note down the value of this property. (Say, Struct)

Now modify your code like this.


IFbrfuResultNode assignedRoles = wdContext.nodeFbrfuResponse().nodeFbrfuResult();
IFbrfuResultElement role = null;

int numAssignedRoles = assignedRoles.size();
for (int i = 0; i < numAssignedRoles; i++) {
    role = assignedRoles.getFbrfuResultElementAt(i);
    Struct s = new Struct();
    s.setValue(role.getId());
wdContext.currentMapUserToBusinessRolesElement().modelObject().addmapBusRoleid(s);
}

wdContext.currentMapUserToBusinessRolesElement().setUserId(
wdContext.currentFindBusRolesForUserElement().getUserId();
                                                        );
wdContext.currentMapUserToBusinessRolesElement().modelObject().execute();

This will definitely add the suitable values to your EJB.

~ Bala

darren_hague
Contributor
0 Kudos

Hi Bala,

I understand now that you are talking about setting the values on the model object, not on the context node.

So, I have edited my code so it is now:


IFbrfuResultNode assignedRoles = wdContext.nodeFbrfuResponse().nodeFbrfuResult();
IFbrfuResultElement role = null;

int numAssignedRoles = assignedRoles.size();
long[] rolesToAssign = new long[numAssignedRoles];

for (int i = 0; i < numAssignedRoles; i++) {
	role = assignedRoles.getFbrfuResultElementAt(i);
	rolesToAssign[ i ] = role.getId();
}
wdContext.currentMapUserToBusinessRolesElement().modelObject().setBusRoleid(rolesToAssign);
wdContext.currentMapUserToBusinessRolesElement().setUserId(
    wdContext.currentFindBusRolesForUserElement().getUserId());

wdContext.currentMapUserToBusinessRolesElement().modelObject().execute();

This now works and successfully sends the long[] array to the web service - many thanks for your help.

All the best,

Darren

darren_hague
Contributor
0 Kudos

OK, something very strange is happening now.

The array is passed through to the EJB alright, but for some reason each time I call the EJB, the array received by the EJB contains the values from the sent array, <i>plus all the values from previous calls</i> - in other words, every time the method is called it receives a bigger and bigger array.

I've checked with debug code, and the array being set on the modelObject is definitely the right size.

Obviously there's some kind of "clear down" method call I'm missing somewhere - any ideas, anyone?

Cheers,

Darren

Former Member
0 Kudos

Hi,

Everytime I had a similar problem it was due to not clearing (invalidating) my context node prior to model execution.

e.g. wdContext.nodeResult.invalidate();

Good luck!

Roelof

darren_hague
Contributor
0 Kudos

Thanks Roelof - that didn't help, unfortunately.

What did solve the problem was to move the object creation and binding from wdInit() to just above my previous code.


Request_TechBusRoleViDocument_mapUserToBusinessRoles mapUserToBusinessRoles = 
    new Request_TechBusRoleViDocument_mapUserToBusinessRoles();
wdContext.nodeMapUserToBusinessRoles().bind(mapUserToBusinessRoles);

Cheers,

Darren

Answers (0)