无法获取JSF应用程序中呈现的selectManyCheckbox
我的问题是,我无法在简单的Jsf应用程序中呈现h:selectManyCheckbox组件。虽然h:selectBooleanCheckbox和h:commandButton在输出上正常显示,但selectManyCheckbox不显示。下面的代码缺少什么来渲染组件无法获取JSF应用程序中呈现的selectManyCheckbox,jsf,jboss,ejb,Jsf,Jboss,Ejb,我的问题是,我无法在简单的Jsf应用程序中呈现h:selectManyCheckbox组件。虽然h:selectBooleanCheckbox和h:commandButton在输出上正常显示,但selectManyCheckbox不显示。下面的代码缺少什么来渲染组件 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.co
<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>
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;
}
}
@ManagedBean
@会议范围
公共类Hello实现了可序列化{
私有静态最终长serialVersionUID=1L;
私人名单客户;
私有布尔foo;
公众你好{
客户=新的ArrayList();
客户。添加(“客户1”);
客户。添加(“客户3”);
客户。添加(“客户2”);
客户。添加(“客户4”);
//foo=真;
}
公共列表getCustomers(){
返回客户;
}
公共布尔值isFoo(){
返回foo;
}
}
检查下面修改的代码
<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>
在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;
}
}
@ManagedBean
@会议范围
公共类Hello实现了可序列化{
私有静态最终长serialVersionUID=1L;
公共字符串[]customerSelected;
私人名单客户;
私有布尔foo;
公众你好{
客户=新的ArrayList();
客户。添加(“客户1”);
客户。添加(“客户3”);
客户。添加(“客户2”);
客户。添加(“客户4”);
//foo=真;
}
公共列表getCustomers(){
返回客户;
}
公共布尔值isFoo(){
返回foo;
}
字符串[]getCustomerSelected(){
返回选定的客户;
}
void setCustomerSelected(字符串[]customerSelected){
this.customerSelected=customerSelected;
}
}
您需要在您的