简体   繁体   中英

Cannot get selectManyCheckbox rendered in JSF application

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;
}

}

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;
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM