Dynamicly enable/diable checkboxes in jsf with primefaces

I have a datatable with dynamicly generated data from a database. The user is able to select/unselect rows but only these which are not set as mustSelect from the database.

My Bean

        public boolean isDisabled () {
    if (evState == EvaluationState.MUST_EVALUATE) {
        return true;
    } else {
        return false;
    }
}

public boolean isChecked() {
    if (evState == EvaluationState.EVALUATE
            || evState == EvaluationState.MUST_EVALUATE) {
        return true;
    } else {
        return false;

    }
}

and my xhtmlCode:

< p:selectBooleanCheckbox value="#{myBean.checked}" disabled = "#{myBean.disabled }"/>

which is currently not working like I want it. All check boxes are selected. At compile time I don´t know which check box will enabled or not that's why I have the method disabled.

I would be very happy if someone has a solution how to set disabled dynamically.


Your model should contain 2 attributes to handle these operations, not your controller.

//defining the model
public class Data {
    private String name;
    //you get the idea...
    private boolean checked;
    private boolean disabled;
    //getters and setters...
}

//defining the controller
@ViewScope
public class MyBean {
    private List<Data> lstData;

    public MyBean() {
        //initialize data...
    }

    //getter and setter
}

The view

<h:dataTable value="#{myBean.lstData}" var="data">
    <h:column>
        <h:outputText value="#{data.name}" />
    </h:column>
    <h:column>
        <p:selectBooleanCheckbox value="#{data.checked}" disabled = "#{data.disabled }"/>
    </h:column>
</h>dataTable>

in that way, every row has its own checked and disabled data value.

链接地址: http://www.djcxy.com/p/68542.html

上一篇: 使用JavaScript获取widgetVar或检查/取消选中所有其他PrimeFaces复选框

下一篇: 使用primefaces在jsf中动态启用/禁止复选框