【问题标题】:Put new component inside existent composition将新组件放入现有组合中
【发布时间】:2015-11-06 17:03:10
【问题描述】:

我是 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。

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

提前谢谢...

【问题讨论】:

    标签: jsf jsf-2.2 composite-component


    【解决方案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 是另一个用法示例。

    【讨论】:

    • 谢谢...按我的需要工作。
    • 哇,你不知道你的回答在过去 5 年里对我有什么帮助......我在这里只是为了非常感谢你,这是我学到的第一个也是最好的课程之一这里...
    猜你喜欢
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2011-06-24
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多