2011-03-10 77 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> 

干杯。

哈罗