I am facing an issue "Empty id attribute is not allowed in JSF" while using the below mentioned composite component for a group of buttons (button's count can be 1 to 3) (I use Mojarra 2-0-8 on Tomcat-7) .
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="buttonCount" />
<composite:attribute name="button1Id" />
<composite:attribute name="button1Style" />
<composite:attribute name="button1Action" />
<composite:attribute name="button2Id" />
<composite:attribute name="button2Style" />
<composite:attribute name="button2Action" />
<composite:attribute name="button3Id" />
<composite:attribute name="button3Style" />
<composite:attribute name="button3Action" />
</composite:interface>
<composite:implementation>
<h:commandButton rendered = "#{cc.attrs.buttonCount ge '1'}" id="#{cc.attrs.button1Id}" styleClass="#{cc.attrs.button1Style}">
<f:ajax listener="#{cc.attrs.button1Action}" immediate="true"/>
</h:commandButton>
<h:panelGroup rendered = "#{cc.attrs.buttonCount ge '2'}">
<h:commandButton id="#{cc.attrs.button2Id}" styleClass="#{cc.attrs.button2Style}">
<f:ajax listener="#{cc.attrs.button2Action}" immediate="true"/>
</h:commandButton>
</h:panelGroup>
<h:panelGroup rendered = "#{cc.attrs.buttonCount eq '3'}">
<h:commandButton id="#{cc.attrs.button3Id}" styleClass="#{cc.attrs.button3Style}">
<f:ajax listener="#{cc.attrs.button3Action}" immediate="true"/>
</h:commandButton>
</h:panelGroup>
</composite:implementation>
</html>
Use of the above CC.
<Buttons:myButton txtHeader="Title" txtDescription="text1"
txtAction="TextAction." button1Style="btnSave" buttonCount ="1" button1Id="btnSaveConf" button1Action="#{MyBean.save()}"></Buttons:myButton>
is there any better way to dynamically generate buttons based on a count or any simillar input form the main page. note:- id, styles and action should differ in name.