JSF Primeface Composite Component Example (To reuse component)
Create composite component example: checkbox.
setup facelet-taglib in META-INF Folder:
<facelet-taglib version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"> <namespace>http://www.somelink.com/somelink/composite</namespace> <tag> <tag-name>compositeBox</tag-name> <component> <resource-id> component-path/compositeBox.xhtml </resource-id> </component> </tag> </facelet-taglib>
create composite (compositeBox.xhtml):
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:composite="http://java.sun.com/jsf/composite"> <composite:interface> <composite:attribute name="SelectCheckbox" /> <composite:attribute name="valueItem" /> <composite:attribute name="value" /> <composite:attribute name="bean" /> <composite:attribute name="update" /> <composite:attribute name="disable" /> </composite:interface> <composite:implementation> <p:selectManyCheckbox id="idCheckbox" value="#{cc.attrs.value}" disabled="#{cc.attrs.disable}"> <p:ajax event="change" update="#{cc.attrs.update}" listener="#{cc.attrs.bean.selectAll}"/> <f:selectItem itemLabel="ALL" itemValue="all" /> <f:selectItems value="#{cc.attrs.valueItem}" var="select" itemLabel="#{select.code.concat(' - ').concat(select.name)}" itemValue="#{select.code}" /> </p:selectManyCheckbox> </composite:implementation> </ui:composition>
To use created composite component:
declare in ui:composition
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:usehere="http://www.somelink.com/somelink/composite">
to use component:
<usehere:compositeBox id="idCheckBoxList" update=":from" valueItem="#{bean.item}" bean="#{bean}" value="#{bean.CheckBoxList}" disable="#{bean.isEdit}"/>












