JSF多个复选框选择

时间:2011-06-13 07:12:03

标签: java jsf primefaces

我选中复选框并提交按钮。提交按钮操作执行并导航同一页面,复选框选择甚至没有得到复选框值为真。

PrimeFaces 3.0.M1 Mojarra 2.0.3(FCS b03) apache tomcat

代码:

public class CheckBoxBean {

    private List<String> list = new ArrayList<String>();
    private String[] selectedList=null;
    public CheckBoxBean(){
        list.add("One");
        list.add("Two");
        list.add("Three");
        list.add("Four");
        list.add("Five");
    }

    public String submit(){
        System.out.println("Submit Select List size : "+selectedList.length);
        return "multiplecheckbox.jsf";
    }
    public void setList(List<String> list) {
        this.list = list;
    }

    public List<String> getList() {
        return list;
    }

    public void setSelectedList(String[] selectedList) {
        this.selectedList = selectedList;
        System.out.println("SET Select List size : "+selectedList.length);
    }

    public String[] getSelectedList() {
        if(selectedList!=null)
            System.out.println("GET Select List size : "+selectedList.length);
        return selectedList;
    }

}

multiplecheckbox.xhtml

p:dataTable value="#{checkBoxBean.list}" var="it" selection="#{checkBoxBean.selectedList}"> p:column selectionMode="multiple"/> 
p:column>
#{it} 
</p:column> 
</p:dataTable> 
h:commandButton value="Submit" action="#{checkBoxBean.submit}"/>

0 个答案:

没有答案