将新组件放在现有组合

时间:2015-11-06 17:03:11

标签: jsf jsf-2.2 composite-component

我是Java Web的新手,我只是在学习英语...... 我有多个复合组件,工作正常,例如,这个代码

<composite:interface>
   <composite:attribute name="usernameValue" />
</composite:interface>
<composite:implementation>

<h:form>
   <h:outputText id="username" value="#{cc.attrs.usernameValue}" />
</h:form>

当我需要使用这个组件时,我只是这样做:

<myComposite:myComponent usernameValue="My user name value"/>

这样可以。

但是,如果我需要在之前创建的组件中放入更多组件,该怎么办,例如:

<h:form>
    <h:outputText id="username" value="My text 1" />
    <p:commandButton value="New button 2"/>
    <p:commandButton value="New button 3"/>
    <p:commandButton value="New button 4"/>
<h:form/>

有没有办法做类似的事情:

<myComposite:myComponent usernameValue="This will render default inside composite output text">
    <p:commandButton value="New button 1 to render inside my composite"/>
    <p:commandButton value="New button 2 to render inside my composite"/>
    <p:commandButton value="New button 3 to render inside my composite"/>
<myComposite:myComponent/>

我正在学习,这次我根据我将使用的组件重新创建我需要使用属性render="true or false"的所有复合,但这就像XGH。

对不起我的英语,我知道我需要改进它...

提前致谢...

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,那么您尝试实现的是标记insertChildren的作用。

在您的示例中,它将是:

<composite:implementation>
   <h:form>
      <h:outputText id="username" value="#{cc.attrs.usernameValue}" />
      <composite:insertChildren />
   </h:form>
</composite:implementation>

然后按照您的意图使用该组件:

<myComposite:myComponent usernameValue="This will render default inside composite output text">
    <p:commandButton value="New button 1 to render inside my composite"/>
    <p:commandButton value="New button 2 to render inside my composite"/>
    <p:commandButton value="New button 3 to render inside my composite"/>
<myComposite:myComponent/>

并且commandButtons将放置在定义insertChildren标记的位置。

Here是其使用的另一个例子。

相关问题