开发者

About a checkbox on datatable

开发者 https://www.devze.com 2023-02-09 18:35 出处:网络
I want to use checkbox on datatable like that : <h:selectBooleanCheckbox styleClass=\"selectBooleanCheckbox\" valueChangeListener=\"#{CompletedInventoriesBean.changeUID}\" value=\"#{CompletedInve

I want to use checkbox on datatable like that :

 <h:selectBooleanCheckbox styleClass="selectBooleanCheckbox" valueChangeListener="#{CompletedInventoriesBean.changeUID}" value="#{CompletedInventoriesBean.isChecked(userinventorieswithuser.id)}" id="chkUser">
           <f:ajax event="change" process="chkUser"></f:ajax&开发者_如何学Pythongt;
</h:selectBooleanCheckbox>

My uids are on the Session. And I want to user that clicks checkbox and I am adding or removing that ids on the session.

There is no problem, I could handle the values on the session an beans.

But during the click on the checkboxes, I get JavaScript alert like below:

serverError: class javax.faces.component.UpdateModelExcepton/sections/completed.xhtml @29,244 value="#{CompletedInventoriesBean.isChecked(userinventorieswithuser.id)}": Property 'isChecked' not found on type main.com.brad.services.CompletedInventoriesBean

my isChecked method like that :

public boolean isChecked(int z) {
    boolean exist = false;
    for(int i=0; i < selectedSessionUI.getSessionInventories().size(); i++) {
        if (selectedSessionUI.getSessionInventories().get(i) == z) exist = true;
    }
    return exist;
}

Why I get this alert? This is the only think that I stucked in that page.

Thanks in advance


You can't bind the value attribute to a method taking arguments. It should be bound to a property which is represented by a pure getter and setter.

In this particular case, you'd rather like to use a Map<Long, Boolean> instead.

private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();

@PostConstruct
public void init() {
    for (int id : selectedSessionUI.getSessionInventories()) {
        checked.put(Long.valueOf(id), true);
    }
}

public Map<Long, Boolean> getChecked() {
    return checked;
}

in combination with

<h:selectBooleanCheckbox value="#{CompletedInventoriesBean.checked[userinventorieswithuser.id]}">

To collect all checked rows, just loop through checked map in the action method.

(no setter is required since [] will use put() and get() on Map itself)


You are getting this error because you can't pass parameters to the valueChangeListener method. Similar question to this one was answered here.

More on this can be found under this link.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号