tehackio
tehackio

Reputation: 115

Should a composite component really require namingcontainer interface?

I want to create a composite componet that can iterate with others. The problem is that composite componet is a namingcontainer and a simple selectOnMenu change and refresh other selectOnMenu do not is possible because "id" given to selectOnMenu is combo1:combo and can't see combo2:combo.

The best situation would be form1:combo1 and form1:combo2, then, combo1 and combo2 uses uinamingcontainer of h:form. This link talks about this but no solution. https://cwiki.apache.org/MYFACES/create-a-non-namingcontainer-composite-component.html

Another try but don't works. p:commandbutton can't see id of div inside of CC. Obtaining the clientId of the parent of a JSF2 composite component

<p:commandButton value="asd" partialSubmit="true" process="@this" update="fooId"/>  
    <cf:label id="fooId" title="xxxxx" />[index.xhtml]




<composite:interface componentType="RootComponent" preferred="false">
    <composite:attribute name="title" />
</composite:interface>

<composite:implementation>
<div id="#{cc.immediateParent.clientId}:#{cc.id}">
#{currentDate}
<h:panelGroup id="#{cc.clientId}" layout="block">
    <p:outputLabel id="#{cc.clientId}_lb" value="#{cc.attrs.title}">
        <composite:insertChildren />
    </p:outputLabel>
</h:panelGroup>
</div>
</composite:implementation>[label.xhtml](compositecomponent)

Upvotes: 2

Views: 2426

Answers (1)

BalusC
BalusC

Reputation: 1109362

Should a composite component really require namingcontainer interface?

Yes. Otherwise you would end up with "Duplicate component ID" errors coming from the composite component implementation when using multiple of them in the same parent naming container.

If you're absolutely positive that you don't want a NamingContainer based component, then rather create a tag file instead. It only requires some .taglib.xml boilerplate.

See also:


Another try but don't works. p:commandbutton can't see id of div inside of CC

Your composite implementation is invalid. In order to reference a composite properly by ajax, you need a plain HTML <div> or a <span> with exactly the ID of #{cc.clientId}.

E.g.

<composite:implementation>
    <div id="#{cc.clientId}">
        #{currentDate}
        <h:panelGroup layout="block">
            <p:outputLabel id="#{cc.clientId}_lb" value="#{cc.attrs.title}">
                <composite:insertChildren />
            </p:outputLabel>
        </h:panelGroup>
    </div>
</composite:implementation>

(I have by the way the impression that the <h:panelGroup> is superfluous, you can safely omit it; further the id="#{cc.clientId}_lb" can better be id="label" or something to minimize repetition/duplication)

See also:

Upvotes: 5

Related Questions