Primefaces数据表不遵循渲染标签的条件恢复 [英] Primefaces datatable not obeying conditional restiriction of rendered tag

查看:63
本文介绍了Primefaces数据表不遵循渲染标签的条件恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的代码:

<p:outputPanel id="conditionalPanel">
    <p:panel rendered="#{object.category.string == 'foo'}">
        <ui:param name="foo" value="#{object}"/>
        <h:panelGrid columns="3" id="fooAssignmentsuttonGrid">
            <h:outputLabel for="barToAdd" styleClass="desc" value="#{foobarzooUIData.label}"/>
            <h:selectOneMenu id="barToAdd" value="#{fooController.barToAdd}">
                <f:selectItems value="#{barsToAddAssignments}"
                               var="foobarzoo" itemValue="#{foobarzoo}" 
                               itemLabel="#{foobarzooUIData.buildLabelForObject(foobarzoo)}"/>
            </h:selectOneMenu>
            <p:commandButton value="#{text['button.add']}" process="@this barToAdd" 
                             update="assignmentDetail" disabled="#{empty barsToAddAssignments}"
                    action="#{fooController.createNewAssignment(foo)}">
            </p:commandButton>
        </h:panelGrid>
        <p:outputPanel id="fooAssignmentsTable">
            <p:dataTable value="#{utils:toList(foo.fooAssignments)}" var="assignment">
                <!-- p:columns here etc..-->
            </p:dataTable>
        </p:outputPanel>

        <p:outputPanel id="assignmentDetail">
            <p:panel rendered="#{not empty fooController.selectedAssignment}" style="margin-top: 30px;">
                <h:panelGrid id="assignmentDetailForm" styleClass="formsTable" columns="2">
                   <!-- Some kick ass code here -->
                </h:panelGrid>
            </p:panel>
        </p:outputPanel>
    </p:panel>
</p:outputPanel>

问题是,当我点击此页面时

The problem is, when I hit this page when

 object.category.string == 'foo'

不满意,我仍然得到:

/test.xhtml @264,147 value="#{utils:toList(foo.fooAssignments)}": The class 'com.foo.bar.too does not have the property 'fooAssignments'.

是的,我知道此类没有此属性,但是完全不应对此进行评估,不是吗?

Yes, I know this class does not have this property, but this should not be evaluated at all, isn't it?

我在这里想念什么?

推荐答案

很遗憾,您没有发布完整的堆栈跟踪信息,因为这通常代表了完整的答案,我可以将其翻译成外行的用语.

It's unfortunate that you didn't post the full stack trace, as that usually represents the whole answer at its own which I could just translate into layman's terms.

通常,这确实会在<ui:repeat>中已观察到此问题,并已在该方面解决此问题.另请参阅以下相关问题与解答:在ui:repeat中有条件呈现的子类上的PropertyNotFoundException /a>.

Generally this will indeed happen during a component tree visit whereby the rendered attribute is not obeyed. The mention of the stack trace and the actual versions being used should reveal whether it's a "feature" or actually a bug in either the JSF impl being used, or in PrimeFaces. Generally I'd say that this would be a bug. This problem has before been observed with Mojarra's <ui:repeat> and has been fixed in that side. See also this related Q&A: PropertyNotFoundException on conditionally rendered subclasses in ui:repeat.

如果升级到最新的JSF impl和PrimeFaces版本无济于事,那么最好的选择是有条件地 build 而不是有条件地渲染视图. JSTL在这方面非常有帮助.另请参见 JSF2 Facelets中的JSTL ...有意义吗?

If upgrading to latest JSF impl and PrimeFaces version doesn't help, then your best bet is to conditionally build the view instead of conditionally render the view. JSTL is very helpful in this. See also JSTL in JSF2 Facelets... makes sense?

<c:if test="#{object.category.string == 'foo'}">
    <p:panel>
        ...
    </p:panel>
</c:if>

这篇关于Primefaces数据表不遵循渲染标签的条件恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆