javax.el.propertynotfoundexception:类“没有可读属性”



我几乎遇到了所有相关问题,但找不到答案,因为我没有问题的原因错误结果。

我已经实现了PrimeFaces selectbooleanbutton 元素,仅根据该元素包含Bean代码。该错误意味着系统无法读取托管Bean的属性,但是我有适当的Getter/Setter方法,因为它应该是布尔属性的。以下是参考的代码:

查看

    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
  <ui:composition template="/templates/common/public.xhtml">
    <ui:define name="title">Search</ui:define>
    <ui:define name="content">
      <div class="ui-grid ui-grid-responsive">
        <div class="ui-grid-row">
          <div class="ui-grid-col-10" id="mainCol">
            <h:form id="search">
              <h:panelGrid columns="2" cellpadding="5">
              <h:outputText value="Choose: " />
              <p:selectBooleanButton id="preference" value="#{searchForm.preference}" onLabel="Yes" offLabel="No" style="width:60px" />
            </h:form>
          </div>
        </div>
      </div>
    </ui:define>
  </ui:composition>
</html>

bean:

@Named
@SessionScoped
public class SearchForm {
  private boolean preference;
  public boolean isPreference() {
      return preference;
  }
  public void setPreference(boolean preference) {
      this.preference = preference;
  }
}

错误:

[glassfish 4.1] [SEVERE] [] [javax.enterprise.resource.webcontainer.jsf.application] [tid: _ThreadID=26 _ThreadName=http-listener-1(2)] [timeMillis: 1488954548903] [levelValue: 1000] [[
  Error Rendering View[/search/searchForm.xhtml]
javax.el.PropertyNotFoundException: /search/searchForm.xhtml @49,156 value="#{searchForm.preference}": The class 'com.pc.SearchForm' does not have a readable property 'preference'.

请建议。

这个问题已经很长时间了,但是要发布此答案只是为了提及原因并关闭问题。

它是 Glassfish不捡起更改并重新启动其解决问题。因此,如果您确定自己的更改并且仍然会遇到错误,我想也可以怀疑服务器:)

这是一个古老的问题,但这可能会对某人有所帮助。我的Boolean有类似的问题。将getter方法从isXxx更改为getXxx解决了它。例如:

public boolean getPreference() {
    return preference;
}

最新更新