cancel
Showing results for 
Search instead for 
Did you mean: 

Reflection of context node elements

Former Member
0 Kudos

Hi,

we have a problem with reflection on context node elements of the type IWDNodeElement. We cannot get all methods via the IWDNodeElement.getClass().getMethods() function.

Following example:

In the context we have:

Context

User (Node)

userName (Attribute)

userPassword (Attribute)

We create a new node element of that type that we want to fill by reflection.


IPrivateUserView.IUserElement element = wdContext.nodeUser().createUserElement();
wdContext.nodeUser().addElement(element);

Then in another funtion we try to fill the userName and userPassword fields by getting the setter methods of the IUserElement:


Method[] methods = element.getClass().getMethods();

And that were the problem occurs! The methods that are given back are just the methods of the IWDNodeElement class but not of the IUserElement class.

Maybe it's because this IUserElement class is a generated (by webdynpro) static inner class of an interface and reflection can not handle this?

Any hints would be nice

Fabian

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hy Fabi,

you can use IWDNodeElement.setAttributeValue("Attribute",object); and IWDNodeElement.getAttributeValue("Attribute"); for reading. IWDNodeElement.getClass().getDeclaredFields(); return all attributes of the nodeElement.

Former Member
0 Kudos

Hi,

Use this:

element.userName() and element.userPassword() and similarly set methods for both.

Regards,

Murtuza

Former Member
0 Kudos

Hi!

Thanks, but I guess I didn't understand you. There are <b>no</b> methods given back that could set the properties. There are just the methods of the normal IWDNodeElement. But we need the methods for our own properties to set them automatically.

Regards,

Fabian

Former Member
0 Kudos

Hi,

I don't know want you want to do with

Method[] methods = element.getClass().getMethods();

If you just want to set the values in the Context you can just go for using:

wdContext.currentUserElement().setPassword("VALUE");
wdContext.currentUserElement().setName("VALUE");

Or If you have a collection you can create elements in a loop like

you posted in the beginning of this thread:

IPrivateUserView.IUserElement element = wdContext.nodeUser().createUserElement();
wdContext.nodeUser().addElement(element);

element.setUserName("VALUE");
element.setUserPassword("VALUE");

Regards,

Dennis

Former Member
0 Kudos

Hi Fabian,

For all the attributes that you create in your context, the framework provides you the getters and setters for them automatically and you can access them as being shown by me in the previous reply.

Regards,

Murtuza

Former Member
0 Kudos

Hi!

Maybe I didn't explain it exactly enough. That was just an example with the IUserElement. In our application we have multiple nodes with attributes. Those attributes should be filled with data from POJO's (that we get from a bean) that have the same attributes. Therefore we want to a create a mechanism that reads the attribute methods (getter/setter) from the node and uses them to fill the attributes with the corresponding values from the POJO. It should be a mechanism that runs with all IWDNodeElements and therefore we want to use reflection just to be as abstract as we can.

Regards

Fabian

Former Member
0 Kudos

But why not just use the generic context API?

For example

IWDNodeElement.setAttributeValue(String attributeName, Object value)

Armin

Former Member
0 Kudos

Yes then in this case it won't return you the methods for your user defined attributes in the node and will only return the methods of IWDNode

Regards,

Murtuza

Former Member
0 Kudos

But why won't it return those methods? If I take a look in the generated java files the methods are there.

Regards

Fabian