关于datatable的复选框 [英] About a checkbox on datatable
问题描述
我想在datatable上使用复选框:
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>
</h:selectBooleanCheckbox>
我的用户名在会话中。而且我想要用户点击复选框,我在会话中添加或删除该ID。
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.
没有问题,我可以处理bean上的值。
There is no problem, I could handle the values on the session an beans.
但是点击复选框时,我会收到以下JavaScript提示:
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类型main.com.brad.services.CompletedInventoriesBean
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
我的isChecked方法像这样:
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.
提前感谢
推荐答案
您不能将值
属性绑定到接受参数的方法中。它应该绑定到一个由纯粹的getter和setter表示的属性。
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;
}
与
<h:selectBooleanCheckbox value="#{CompletedInventoriesBean.checked[userinventorieswithuser.id]}">
要收集所有已检查的行,只需循环选择 $ c $
To collect all checked rows, just loop through checked
map in the action method.
(不需要setter,因为 []
将使用 put()
和 get()
on Map
本身) / em>
(no setter is required since []
will use put()
and get()
on Map
itself)
这篇关于关于datatable的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!