i have jsf 2.2 composite component used more once on same page.
@facescomponent("mycomponent") public class mycomponent extends uicomponent { public void test() { system.out.printlin(getattributes("value")); } }
component xhtml:
<composite:interface componenttype="mycomponent"> <composite:attribute name="value" required="true" type="java.lang.string" /> </composite:interface> <composite:implementation> <a4j:jsfunction name="test" action="#{cc.test()}" execute="input" /> <s:span id="input"> <h:inputtext value="#{cc.attrs.value}" onclick="test()" /> </s:span> </composite:implementation>
page xhtml
<my:mycomponent value="#{bean.value}" /> -- line 1 <my:mycomponent value="#{bean2.value}" /> -- line 2
when click on first mycomponent, calls test() prints value of bean2.value instead of bean.value. if remove line 2 prints bean.value. thought call getattributes() value current composite component, seems getting value last composite component on page. explain me how attributes supposed work or missing?
here solution, id attribute appended jsfunction distinguish other same components on page:
<composite:interface componenttype="mycomponent"> <composite:attribute name="id" type="java.lang.string" /> <composite:attribute name="value" required="true" type="java.lang.string" /> </composite:interface> <composite:implementation> <a4j:jsfunction name="#{cc.attrs.id}test" action="#{cc.test()}" execute="input" /> <s:span id="input"> <h:inputtext value="#{cc.attrs.value}" onclick="#{cc.attrs.id}test()" /> </s:span> </composite:implementation>