I have a UserPass class which has 2 properties: User user; String password User has other properties like username, systemId etc.
I have a call to setProperty ("username", value) on UserPass, which should actually set the property of the User that is inside the UserPass.
Can someone suggest how this can be done? I have looked at PropertyUtils from apache commons beanutils by get the following on: PropertyUtils.setProperty(UserPass.getUser(), "username", value), but this throws an java.lang.IllegalArgumentExceptio开发者_Python百科n: No bean specified
Looks like you need to use the instance of the UserPass object. The way you are doing it makes it look as if you are calling a static method on the class to getUser(). Say you have a UserPass declared as up like this:
UserPass up = new UserPass();
//set the various properties including the User object
then
PropertyUtils.setProperty(up.getUser(), "username", value);
will work but only if getUser() returns a non-null object.
精彩评论