Reputation: 9232
My problem is that I cannot render the h:selectManyCheckbox component in a simple Jsf application. Although h:selectBooleanCheckbox and h:commandButton appear normally on the output, the selectManyCheckbox does not. What lacks the following code of, to get the component rendered?
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form>
<h:selectManyCheckbox value="#{hello.customers}"></h:selectManyCheckbox><br />
<h:selectBooleanCheckbox value="#{hello.foo}" /><br/>
<h:commandButton action="response.xhtml" value="Click me" />
</h:form>
</html>
The Bean Class:
@ManagedBean
@SessionScoped
public class Hello implements Serializable{
private static final long serialVersionUID = 1L;
private List<String> customers;
private boolean foo;
public Hello(){
customers = new ArrayList<String>();
customers.add("Cust1");
customers.add("Cust3");
customers.add("Cust2");
customers.add("Cust4");
//foo = true;
}
public List<String> getCustomers() {
return customers;
}
public boolean isFoo() {
return foo;
}
}
Upvotes: 0
Views: 344
Reputation: 152
Check the Below Modified Code
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:form>
<h:selectManyCheckbox value="#{hello.customerSelected}">
<f:selectItems value="#{hello.customers}" />
</h:selectManyCheckbox><br />
<h:selectBooleanCheckbox value="#{hello.foo}" /><br/>
<h:commandButton action="response.xhtml" value="Click me" />
</h:form>
</html>
To the Bean Class add one more field to store the Result of Checked Elements.
@ManagedBean
@SessionScoped
public class Hello implements Serializable {
private static final long serialVersionUID = 1L;
public String[] customerSelected;
private List<String> customers;
private boolean foo;
public Hello() {
customers = new ArrayList<String>();
customers.add("Cust1");
customers.add("Cust3");
customers.add("Cust2");
customers.add("Cust4");
// foo = true;
}
public List<String> getCustomers() {
return customers;
}
public boolean isFoo() {
return foo;
}
String[] getCustomerSelected() {
return customerSelected;
}
void setCustomerSelected(String[] customerSelected) {
this.customerSelected = customerSelected;
}
}
Upvotes: 2