jsf 2.0 bean 扩展了另一个 bean 目标无法访问,'null'返回空值
public class SuperUser extends User implements Serializable{
private static final long serialVersionUID = 1L;
private String username;
private String pin;
//getters and setters
}
当我在托管 bean 中使用它并尝试在facelets文件中访问它时,
<h:inputText id="firstName" value="#{userManager.superUser.firstName}" required="true" maxlength="30" size="30"/>
我得到一个异常
javax.el.PropertyNotFoundException: /superUser/create.xhtml @18,96 value="#{userManager.superUser.firstName}": Target Unreachable
,这是否意味着如果您想访问它们的属性,您无法扩展java bean?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它只是意味着
#{userManager.superUser}
返回了null
,因此无法对其调用setFirstName()
。 JSF 不会为您创建嵌套对象属性。你必须自己做。要解决此问题,只需确保
#{userManager}
后面的支持 bean 类内部不为 null。例如It just means that
#{userManager.superUser}
returnednull
and hencesetFirstName()
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.User 类中的方法
getFirstName()
是公共的吗?同样,userManager 托管 bean 的 getSuperUser() 是公共的吗?
Is the method
getFirstName()
inside User class public?Similarly, is
getSuperUser()
of the userManager managed bean public?