2011-03-10 78 views
2

類似於here我使用抽象類來鍵入項目集列表 的ui:重複。具體子類覆蓋對GetType()方法,其用於 有條件地呈現其特定性質的各亞型:有條件地呈現JSF中的子類ui:重複標記

<!-- AbstractAction Rule#getActions() --> 
<ui:repeat value="#{rule.actions}" var="action"> 
    <!-- render when "action" instance of NotificationAction --> 
    <h:panelGroup rendered="#{action.type == 'notification'}"> 
    ... UI for NotificationAction properties 
    <h:panelGroup rendered="#{action.type == 'callback'}"> 
    ... 

當在Glassfish 3運行有關於未在列表中的 成員定義的屬性的錯誤其他亞類(PropertyNotFoundException),其發生在 實際上由渲染屬性關閉一個分支。 C:的forEach/C:選擇似乎並不 合適。任何想法如何使渲染真正有條件並繞過 屬性檢查高度讚賞!

謝謝。 哈羅

+0

重複的http://stackoverflow.com/questions/22613193/javax-el-propertynotfoundexception-when-submitting-uirepeat-with-conditionally/ – BalusC 2014-08-12 18:38:35

回答

1

一些測試後,事實證明,該UI:重複組件本身造成的錯誤。 儘管在最後的renderResponse相爲它試圖挽救其子輸入組件的狀態。這縮短的異常轉儲:

Caused by: javax.el.PropertyNotFoundException: ... The class FOO does not have a readable property 'BAR'. 
     at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:104)   
     at com.sun.faces.facelets.component.UIRepeat.saveChildState(UIRepeat.java:343) 
     at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:428) 
     at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:522) 
     at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:926) 
     at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613) 
     at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273) 
     at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127) 
     at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 

特此呈現條件被忽略,EL解釋抱怨不存在的屬性。有一個簡單的解決方案,通過使用H:dataTable中迭代器與單個列代替:

<h:dataTable value="#{rule.systemActions}" var="action"> 
     <c:set var="name" value="#{action.class.simpleName.toLowerCase()}" /> 
     <h:column> 
      <h:panelGroup rendered="#{name == 'notification'}"> 
        <h:outputLabel for="phone">Phone:</h:outputLabel> 
        <h:inputText value="#{action.phone}" id="phone" /> 
      </h:panelGroup> 
      <h:panelGroup rendered="#{name == 'reminder'}"> 
       ... 
      </h:panelGroup> 
     </h:column> 
    </h:dataTable> 

乾杯。

哈羅