【问题标题】:Unable to find facet named 'header' in parent composite component无法在父复合组件中找到名为“header”的构面
【发布时间】:2014-02-13 15:39:45
【问题描述】:

我在 JSF 中使用 primefaces 实现了一个复合组件。

<ui:component ...>
    <cc:interface>
            <cc:facet name="header"/> ...
    <cc:interface>

<cc:implementation>
   <p:dataTable>
    <f:facet name="header">
       <c:choose>
         <c:when test="#{empty cc.attrs.metadata.headerText}">
            <cc:insertFacet name="header" required="true"/>
        </c:when>
        <c:otherwise>
        #{cc.attrs.headerText}
        </c:otherwise>
       </c:choose>
    </f:facet> ...
   </dataTable>
</cc:implementation>

当我在普通页面中使用它时,它可以正常工作,如预期的那样呈现数据表。

<ui:composition>
    <nav:dataTable/>
        <f:facet name="header">
            <h:outputText value="headerText" />
        </f:facet>
</ui:composition>

但是当我在使用上述复合组件的对话框中使用它时,它会抛出

component.xhtml @28,54

无法在父级中找到名为“header”的构面 id 为 'j_idt129' 的复合组件

我正在进行 ajax 调用以在单击链接时调用此对话框。该对话框具有不同的形状,并在控制台中引发此错误。有没有人面对过?任何帮助都是非常可观的。

【问题讨论】:

  • 不应该将构面包含在&lt;nav:dataTable&gt;标签中吗?

标签: jsf jsf-2 primefaces ajax4jsf


【解决方案1】:

cc:insertFacet 插入整个 f:facet 标记,因此您不应将其包装到复合实现中的另一个 f:facet 标记中。当您正在编写自定义 p:dataTable 时,我认为将现有的 header facelet 覆盖为接口声明并使用 JSTL 实用程序有条件地呈现它会更容易:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:composite="http://java.sun.com/jsf/composite"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core">

<h:body>
    <composite:interface>
        <composite:facet name="header" />
        <composite:attribute name="title" />
    </composite:interface>

    <composite:implementation>
        <p:dataTable>
            <!-- If the facet is given at parent, insert it. 
            Otherwise, provide the title given by the attribute -->
            <c:choose>
                <c:when test="#{not empty cc.facets.header}">
                    <composite:insertFacet name="header" />
                </c:when>
                <c:otherwise>
                    <f:facet name="header">
                        #{cc.attrs.title}
                    </f:facet>
                </c:otherwise>
            </c:choose>

            <p:column headerText="column" />
        </p:dataTable>
    </composite:implementation>
</h:body>
</html>

将其用作:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:comp="http://java.sun.com/jsf/composite/comp">

<f:view>
    <h:head />
    <h:body>
        <h:form>
            <comp:myTable title="header">
                <f:facet name="header">
                    <h:outputText value="text" />
                </f:facet>
            </comp:myTable>

            <comp:myTable title="Custom header" />

            <p:commandButton type="button" onclick="dialog.show()"
                value="show in dialog" />

            <p:dialog widgetVar="dialog">
                <comp:myTable title="header">
                    <f:facet name="header">
                        <h:outputText value="text" />
                    </f:facet>
                </comp:myTable>
            </p:dialog>

        </h:form>
    </h:body>
</f:view>
</html>

【讨论】:

    猜你喜欢
    • 2011-02-09
    • 2023-03-23
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 2012-04-09
    • 1970-01-01
    相关资源
    最近更新 更多