【问题标题】:javax.el.PropertyNotFoundException: Property 'selectedUser' not found on type bg.fmi.master.thesis.beans.ProfileBeanjavax.el.PropertyNotFoundException:在类型 bg.fmi.master.thesis.beans.ProfileBean 上找不到属性“selectedUser”
【发布时间】:2014-10-31 02:37:30
【问题描述】:

你知道我的应用为什么会抛出这个异常吗:

WARNING: /myProfile.xhtml @71,27 target="#{profileBean.selectedUser}": Property 'selectedUser' not found on type bg.fmi.master.thesis.beans.ProfileBean
javax.el.PropertyNotFoundException: /myProfile.xhtml @71,27 target="#{profileBean.selectedUser}": Property 'selectedUser' not found on type bg.fmi.master.thesis.beans.ProfileBean
---
Caused by: javax.el.PropertyNotFoundException: Property 'selectedUser' not found on type bg.fmi.master.thesis.beans.ProfileBean

当我的 bean 中有这个属性时:

@ManagedBean(name = "profileBean")
public class ProfileBean implements Serializable {
    private TUser selectedUser = new TUser();

    public TUser getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(TUser selectedUser) {
        this.selectedUser = selectedUser;
    }

.xhtml 代码是这样的:

      <p:dataGrid var="user" value="#{profileBean.userList}">
                            <p:panelGrid columns="2">
        ....
        <p:commandButton id="submit" value="Save changes" actionListener="#{profileBean.editUser()}" >
           <f:setPropertyActionListener target="#{profileBean.selectedUser}" value="#{user}" />
        </p:commandButton>
  </p:dataGrid>

提前致谢!

【问题讨论】:

  • 代码看起来不错。您很可能没有运行您认为正在运行的代码。也就是说,您的环境似乎支持 EL 2.2。为什么不只是action="#{profileBean.editUser(user)}" 而不是这个听众混乱?
  • 它再次抛出异常:原因:javax.el.MethodNotFoundException:/myProfile.xhtml @73,53 action="#{profileBean.editUser(user)}":找不到方法:bg。 fmi.master.thesis.beans.ProfileBean@11e9862.editUser(bg.fmi.master.thesis.model.TUser)。我也编辑了我的方法。在你关于类似问题的一篇文章中,写到 f:attribute 可以使用,我设法使它与这个代码一起工作 但我仍然不清楚为什么它不能以上述其他方式工作。
  • 您很可能没有运行您认为正在运行的代码。
  • 我怎样才能知道我到底在运行什么?
  • 日志中除了这个还有其他错误吗?

标签: jsf jsf-2 primefaces el


【解决方案1】:

我根据你的示例代码做了一个简单的项目。

<h:form>
    <p:commandButton id="submit" value="Save changes" actionListener="#{profileBean.editUser()}" >
       <f:setPropertyActionListener target="#{profileBean.selectedUser}" value="#{user}" />
    </p:commandButton>
</h:form>

没有描述的这样的错误。你的问题来自其他地方。删除不必要的位并尝试隔离问题。您可以更改属性的名称并查看错误是否反映了新名称。确保您没有其他同名的 bean。

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 2017-09-01
    • 2012-05-03
    • 2014-10-20
    • 2013-04-18
    • 2012-06-06
    相关资源
    最近更新 更多