【问题标题】:Included content is rendered twice even it is excluded with rendered attribute包含的内容被渲染两次,即使它被渲染属性排除在外
【发布时间】:2015-05-12 13:12:43
【问题描述】:

在 primefaces 对话框中,我最初显示了一个带有一些输入字段的表单。如果用户单击一个按钮,则会打开一个图像或 pdf,并且该对话框以 p:layout 分隔。为此,我在 editProperty.xhtml 中包含了输入字段的呈现,并在对话框中包含了两次。在 panelGroup 内仅显示输入字段,也在 p:layout 内显示。我排除了 panelGroup 和带有 render 属性的布局。所以我的期望是只有对话框与布局或面板组一起显示。 初始 UI 显示它没有 p:layout,但字段被渲染两次。

<o:form id="editPropertyFormId">
<p:dialog id="editPropertyDialogId" widgetVar="editPropertyDialogVar" modal="true">
    <!-- <c:if test="#{editPropertyContentBL.isContentViewerCollapsed() == false}"> -->
    <p:layout id="editPropertiesLayoutId" style="width: 100%; height: 100%;" onResize="adjustContentViewerSize();"
        widgetVar="editPropertiesLayoutVar" rendered="#{editPropertyContentBL.contentViewerCollapsed == false}">
        <p:layoutUnit id="editPropertiesFieldsLayoutId" position="west" resizable="true" size="400"
            style="padding-right: 5px !important;" collapsible="false">
            <ui:include src="/sections/edit/editProperty.xhtml">
                <ui:param name="idPrefix" value="editPropsInLayout" />
                <ui:param name="editPropertyBLInstance" value="#{editPropertyBL}" />
                <ui:param name="editPropertyContentBLInstance" value="#{editPropertyContentBL}" />
            </ui:include>
        </p:layoutUnit>
        <p:layoutUnit id="editPropertiesContentViewerLayoutId" position="center" resizable="true"
            styleClass="contentViewerLayout">
            <ui:include src="/sections/content/contentViewer.xhtml" />
        </p:layoutUnit>
        </p:layout>
        <!-- </c:if> -->

        <!-- <c:if test="#{editPropertyContentBL.isContentViewerCollapsed() == true}"> -->
        <h:panelGroup rendered="#{editPropertyContentBL.contentViewerCollapsed == true}">
            <ui:include src="/sections/edit/editProperty.xhtml">
                <ui:param name="idPrefix" value="editProps" />
                <ui:param name="editPropertyBLInstance" value="#{editPropertyBL}" />
                <ui:param name="editPropertyContentBLInstance" value="#{editPropertyContentBL}" />
                </ui:include>
        </h:panelGroup>
        <!-- </c:if> -->
</p:dialog>

如果我使用 c:if(代码中未注释),似乎 ui:parameter 不起作用,因为 editProperty.xhtml 中的更新不起作用:

<p:inputText id="#{idPrefix}editPropertyChoiceListValueId"...
<p:commandButton update="#{idPrefix}editPropertyChoiceListValueId"

我收到一个异常,即找不到“editPropseditPropertyChoiceListValueId”。 c:if 中的 ui:include/ui:param 可能有问题?

谢谢 奥利弗

【问题讨论】:

  • 它是一个原始布尔值,在调试期间,它在 UI 的初始构建中始终处于其初始状态 true。只有按钮单击将其更改为 false。

标签: jsf primefaces facelets jsf-2.2


【解决方案1】:

两次渲染内容的问题是在包含的 xhtml 中的 dataTable 的数据绑定:

<h:dataTable binding="#{editPropertyMainTableBinding}"

我用它来获取当前行索引:

<ui:param name="curDummyCssClass" value="editPropertyChoiceDummyCssClass#{editPropertyMainTableBinding.rowIndex}" />

在我消除这个之后,双重渲染就消失了。此外,UI 渲染似乎要快得多。 此外,我通过将内容放在单独的 xhtml 文件中并包含它来删除“c:if test”和渲染的东西:

<ui:include src="#{editPropertyContentBL.contentViewerCollapsed == true ? '/sections/dialog/editPropertyDialogContent.xhtml' : '/sections/dialog/editPropertyWithContentViewerDialogContent.xhtml'}" />

我认为这与双重渲染无关,但删除了不受欢迎的 c:if 标签。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    相关资源
    最近更新 更多