简体   繁体   English

无法在JSF应用程序中获取selectManyCheckbox

[英]Cannot get selectManyCheckbox rendered in JSF application

My problem is that I cannot render the h:selectManyCheckbox component in a simple Jsf application. 我的问题是我无法在简单的Jsf应用程序中呈现h:selectManyCheckbox组件。 Although h:selectBooleanCheckbox and h:commandButton appear normally on the output, the selectManyCheckbox does not. 虽然h:selectBooleanCheckbox和h:commandButton正常出现在输出中,但selectManyCheckbox却没有。 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: Bean类:

@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. 对Bean类添加一个字段以存储已检查元素的结果。

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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