on 10-10-2007 9:10 AM
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
Hy Fabi,
you can use IWDNodeElement.setAttributeValue("Attribute",object); and IWDNodeElement.getAttributeValue("Attribute"); for reading. IWDNodeElement.getClass().getDeclaredFields(); return all attributes of the nodeElement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use this:
element.userName() and element.userPassword() and similarly set methods for both.
Regards,
Murtuza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.