【问题标题】:Declare markup outside cc:implementation and let the cc:implementation include it在 cc:implementation 之外声明标记并让 cc:implementation 包含它
【发布时间】:2014-09-03 15:18:42
【问题描述】:

嗯。 我为 CRUD 创建了一个自定义组件,表单页面是一个参数。 在这种情况下,我需要两个页面,一个用于定义组件,另一个用于表单。

有什么办法吗?

如下:

实施:

组件

<cc:interface>
    <cc:attribute name="formPage" type="java.lang.String" required="true"/>
    .....
</cc:interface>

<cc:implementation>
...
    <h:form id="form-crud">
        <ui:include src="#{cc.attrs.formPage}" />       
    </h:form>
...
</cc:implementation>

第 1 页:crud.xhtml

<ui:define name="content-template" >
    <comp:crud 
        paginaForm="crud-form.xhtml" />
</ui:define>

第 2 页:crud-form.xhtml

<html ...
    <p:panelGrid id="grid-crud" columns="2" >
        <h:outputLabel for="dsName" value="Name: " />
        <p:inputText id="dsName"  value="#{crudBean.dsName}"/>
    </p:panelGrid>  
</html>

新实施(示例)

为了简化,我想在同一页面中包含组件定义和表单,类似这样。可能吗? 我知道我可以使用模板,但自定义组件有更多属性。

新组件

<cc:implementation>
...
    <h:form id="form-crud">
        <XX:SOMETING name="#{cc.attrs.formContent}" />      
    </h:form>
...
</cc:implementation>

新页面 1:new-crud.xhtml

...
<ui:define name="content-template" >
    <comp:crud 
        form="new-form" />

    <XX:SOMETING id="new-form">

        <p:panelGrid id="grid-crud" columns="2" >
            <h:outputLabel for="dsName" value="Name: " />
            <p:inputText id="dsName"  value="#{crudBean.dsName}"/>
        </p:panelGrid>  

    </XX:SOMETING>

</ui:define>
...

【问题讨论】:

  • 这是我第二次修复您问题中的术语错误。这些不是自定义组件。这些是复合组件。要了解差异,请参阅stackoverflow.com/questions/6822000/…
  • 好的@BalusC,收到小费!我会注意的!

标签: jsf jsf-2 facelets markup composite-component


【解决方案1】:

您可以像使用 &lt;f:facet&gt; 一样使用它们,例如&lt;h:dataTable&gt;/&lt;h:column&gt; 页眉/页脚。

首先声明一个带有所需名称的&lt;cc:facet&gt;

<cc:interface>
    <cc:facet name="form" />
</cc:interface>

然后在它应该结束的所需位置声明一个&lt;cc:renderFacet&gt;

<cc:implementation>
    ...
    <h:form>
        <cc:renderFacet name="form" />
    </h:form>
    ...
</cc:implementation>

现在你可以按如下方式使用它:

<comp:crud>
    <f:facet name="form">
        ...
    </f:facet>
</comp:crud>

请注意,这种构造也可以通过&lt;ui:define&gt;/&lt;ui:insert&gt; 机制与“普通”Facelets 标签文件一起使用。

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2023-04-10
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多