【问题标题】:Property 'xxxxxx' not found on type org.richfaces.component.UIRepeat在类型 org.richfaces.component.UIRepeat 上找不到属性“xxxxxx”
【发布时间】:2011-11-15 22:41:30
【问题描述】:

我正在从 JSF 1.2 升级到 JSF 2 和 Richfaces 3.3 到 4。 我尝试了各种版本的 JSF2(2.02、2.06 等),都给出了相同的错误。

我收到以下错误,这让我头疼了好几个小时!

SEVERE: Error Rendering View[/my-testfile.xhtml]
javax.el.PropertyNotFoundException: /templates/components-navigation.xhtml @31,54 rendered="#{component.allowed}": Property 'allowed' not found on type org.richfaces.component.UIRepeat


/templates/components-navigation.xhtml

<a4j:outputPanel rendered="#{loginBean.loggedIn}">

    <a4j:repeat var="menugroup" value="#{componentNavigator.groups}">

        <a4j:region rendered="#{menugroup.itemCount > 0}">

            <div class="panel_menu"> 

                <table class="title" border="0" width="100%">
                  <tr>
                    <td>
                        <h:outputText class="text" value="#{messages[menugroup.id]}" />
                    </td>
                  </tr>
                </table>

                <table class="links" border="0" width="100%">
                    <tbody>
                        <a4j:repeat var="component" value="#{componentNavigator.components}">


                            <a4j:region rendered="#{component.allowed}">

                                <a4j:region rendered="#{component.groupId == menugroup.id}">
                                    <tr class="#{component.current?'active':'unactive'}">
                                        <td>&nbsp;</td>
                                        <td class="text" width="100%">
                                            <h:commandLink action="#{component.getCommandAction}" actionListener="#{componentNavigator.initControllerBean}">                                        
                                                <span style="display:block;">
                                                    #{messages[component.id]}                                       
                                                </span>
                                                <f:attribute name="controllerBean" value="#{component.controllerBean}" />
                                                <f:setPropertyActionListener target="#{componentNavigator.currentComponent}" value="#{component}" />
                                            </h:commandLink>
                                        </td>
                                    </tr>
                                </a4j:region>

                            </a4j:region>

                        </a4j:repeat>           
                    </tbody>
                </table>

            </div>

        </a4j:region>

    </a4j:repeat>

</a4j:outputPanel>

第 31 行是:

<a4j:region rendered="#{component.allowed}">

任何想法为什么找不到该属性?重复组件是否存在已知问题?

【问题讨论】:

    标签: jsf-2 richfaces el


    【解决方案1】:

    #{component} 是一个保留的隐式 EL 对象,它引用当前的 JSF 组件。可以这样使用:

    <h:inputText value="#{bean.value}" styleClass="#{component.valid ? 'ok' : 'error'}" />
    

    在上面的示例中,#{component} 解析为代表当前&lt;h:inputText&gt;UIInput 实例,而该实例又具有isValid() 方法。提交时,当组件出现验证错误时,error 样式类将被设置(例如可能具有红色背景颜色),否则ok 样式类将被设置。就像 JavaScript 中的 this

    你应该给你的作用域变量一个不同的名字。不要不要在 JSF 中使用以下保留的 EL 对象之一的名称:

    【讨论】:

      【解决方案2】:

      您的“组件”bean 需要一个

      public boolean getAllowed() {
          return this.allowed;
      }
      

      public void setAllowed(boolean allowed) {
         this.allowed = allowed;
      }
      

      方法。属性是 bean 中的一个字段,它需要一个公共的 getter 和 setter 方法。大多数 IDE 支持生成这些方法,请注意“Source --> Generate Getter and Setter”之类的内容。

      另一种可能性是直接调用方法。类似的,

      <a4j:region rendered="#{component.isAllowed()}">
      

      带有 bean 代码

      public boolean isAllowed() {
          return this.allowed;
      }
      

      如果您已经在您的 componentNavigator bean 中设置了 getter 和 setter,那么如果您可以将其发布在此处(或其中的一部分)将会很有用。

      理查德

      【讨论】:

      • 我的 bean 中已经有了 getter/setter,它在 jsf1.2 中运行良好(没有对任何 bean 进行任何更改)。看起来它可能与使用“组件”这个词作为我的变量有关。
      【解决方案3】:

      我变了:

      <a4j:repeat var="component" value="#{componentNavigator.components}">
      

      到:

      <a4j:repeat var="myComponent" value="#{componentNavigator.components}">
      

      现在一切都很好:)

      我偶然发现了这个问题,这给了我线索:

      https://issues.jboss.org/browse/RF-8026

      【讨论】:

        猜你喜欢
        • 2019-06-07
        • 2016-09-16
        • 2016-01-10
        • 2015-10-09
        • 2019-11-05
        • 2012-05-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多