0

I'm new in Java Web, and I'm just learning english... I have multiples composite component, that works fine, like, for example, this code

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

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

When I need to use this component, I just do:

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

this works ok.

But, how to do if I need put more components inside this previously created component, like:

<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/>

Is there any way to do something like:

<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/>

I'm learning, and this time I recreate all composite that I need to use with attribute render="true or false" according the components that I will use, but this is like XGH.

Sorry for my english, I know that i need to improve it...

Thanks in advance...

Tiny
  • 27,221
  • 105
  • 339
  • 599

1 Answers1

1

If I understood your question correctly, what your trying to achieve is what the tag insertChildren does.

In your example, it would be like:

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

and then use the component like you intended:

<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/>

And the commandButtons will be placed where the insertChildren tag was defined.

Here is another example of its usage.

Community
  • 1
  • 1
RinaldoDev
  • 985
  • 6
  • 21