jsf 2.0 bean extends another bean Target Unreachable, 'null' returned null [duplicate]
public class SuperUser extends User implements Serializable{
private static final long serialVersionUID = 1L;
private String username;
private String pin;
//getters and setters
}
when I use this in a managed bean and try to access it in the facelets file like this
<h:inputText id="firstName" value="#{userManager.superUser.firstName}" required="true" maxlength="30" size="30"/>
I get an exception
javax.el.PropertyNotFoundException: /superUser/create.xhtml @18,96 value="#{userManager.superUser.firstName}": Target Unreachable
Does that mean the you cannot extend java beans if you want to access their properties?
Thanks
It just means that #{userManager.superUser}
returned null
and hence setFirstName()
cannot be called on it. JSF won't create nested object properties for you. You have to do it yourself.
To fix this, just ensure inside the backing bean class behind #{userManager}
that it's not null. E.g.
private SuperUser superUser = new SuperUser();
Is the method getFirstName()
inside User class public?
Similarly, is getSuperUser()
of the userManager managed bean public?
精彩评论