<!-- This group is for coding -->
<p:growl id="growl" showDetail="true"/>
<h:panelGrid id="triStateGrid" columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage:"/>
<pe:triStateManyCheckbox id="TriBasic"
value="#{triSateManyCheckBoxController.selectedOptionsTriStateBasic}"
layout="pageDirection"
stateOneTitle="not matter"
stateTwoTitle="love it"
stateThreeTitle="dislikes">
<f:selectItems value="#{triSateManyCheckBoxController.basicOptions}"/>
</pe:triStateManyCheckbox>
<h:outputText value="Ajax Behavior with custom icons:"/>
<pe:triStateManyCheckbox id="TriAjax"
value="#{triSateManyCheckBoxController.selectedOptionsTriStateAjax}"
stateOneIcon="pi pi-home"
stateTwoIcon="pi pi-heart"
stateThreeIcon="pi pi-star"
tabindex="2">
<f:selectItem itemLabel="Tamara" itemValue="Tamara"/>
<f:selectItem itemLabel="Mauricio" itemValue="Mauricio"/>
<p:ajax event="change" update="growl" listener="#{triSateManyCheckBoxController.addMessage}"/>
</pe:triStateManyCheckbox>
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="PF('dlg').show()"/>
<p:dialog header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg" width="400">
<p:outputPanel id="display">
<p:dataList value="#{triSateManyCheckBoxController.selectedOptionsTriStateBasic.keySet().toArray()}"
var="optionsB">
#{optionsB} state = #{triSateManyCheckBoxController.selectedOptionsTriStateBasic.get(optionsB)}
</p:dataList>
<p:dataList value="#{triSateManyCheckBoxController.selectedOptionsTriStateAjax.keySet().toArray()}"
var="optionsA">
#{optionsA} state = #{triSateManyCheckBoxController.selectedOptionsTriStateAjax.get(optionsA)}
</p:dataList>
</p:outputPanel>
</p:dialog>
@Named
@ViewScoped
public class TriSateManyCheckBoxController implements Serializable {
private static final long serialVersionUID = 20110302L;
private Map<String, String> selectedOptionsTriStateBasic;
private Map<String, String> selectedOptionsTriStateAjax;
private Map<String, State> selectedOptionsTriStateConverted;
private Map<String, State> selectedOptionsTriStateConvertedInline;
private Map<String, String> basicOptions;
public TriSateManyCheckBoxController() {
basicOptions = new HashMap<String, String>();
basicOptions.put("Label for Dog", "Dog");
basicOptions.put("Label for Cat", "Cat");
basicOptions.put("Label for Fish", "Fish");
// default will created with state=0
selectedOptionsTriStateBasic = new HashMap<String, String>();
selectedOptionsTriStateBasic.put("Cat", "1");
selectedOptionsTriStateAjax = new HashMap<String, String>();
selectedOptionsTriStateAjax.put("Tamara", "1");
selectedOptionsTriStateAjax.put("Mauricio", "1");
selectedOptionsTriStateConverted = new HashMap<String, State>();
selectedOptionsTriStateConverted.put("Dog", new State("One"));
selectedOptionsTriStateConverted.put("Cat", new State("One"));
selectedOptionsTriStateConverted.put("Fish", new State("One"));
selectedOptionsTriStateConvertedInline = new HashMap<String, State>();
selectedOptionsTriStateConvertedInline.put("Dog", new State("One"));
selectedOptionsTriStateConvertedInline.put("Cat", new State("Two"));
selectedOptionsTriStateConvertedInline.put("Fish", new State("Three"));
}
public Map<String, String> getSelectedOptionsTriStateAjax() {
return selectedOptionsTriStateAjax;
}
public void setSelectedOptionsTriStateAjax(final Map<String, String> selectedOptionsTriStateAjax) {
this.selectedOptionsTriStateAjax = selectedOptionsTriStateAjax;
}
public Map<String, String> getSelectedOptionsTriStateBasic() {
return selectedOptionsTriStateBasic;
}
public void setSelectedOptionsTriStateBasic(final Map<String, String> selectedOptionsTriStateBasic) {
this.selectedOptionsTriStateBasic = selectedOptionsTriStateBasic;
}
public void addMessage() {
String message = "";
for (final String key : selectedOptionsTriStateAjax.keySet()) {
message += key + "=" + selectedOptionsTriStateAjax.get(key) + " ";
}
final FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "State has been changed", message.trim());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public Map<String, String> getBasicOptions() {
return basicOptions;
}
public void setBasicOptions(final Map<String, String> basicOptions) {
this.basicOptions = basicOptions;
}
public Map<String, State> getSelectedOptionsTriStateConverted() {
return selectedOptionsTriStateConverted;
}
public void setSelectedOptionsTriStateConverted(final Map<String, State> selectedOptionsTriStateConverted) {
this.selectedOptionsTriStateConverted = selectedOptionsTriStateConverted;
}
public Map<String, State> getSelectedOptionsTriStateConvertedInline() {
return selectedOptionsTriStateConvertedInline;
}
public void setSelectedOptionsTriStateConvertedInline(
final Map<String, State> selectedOptionsTriStateConvertedInline) {
this.selectedOptionsTriStateConvertedInline = selectedOptionsTriStateConvertedInline;
}
}