如何将ice:selectManyCheckbox添加到ice:dataTable? [英] How to add ice:selectManyCheckbox to a ice:dataTable?
问题描述
我有一个<ice:dataTable>
,我想向每行添加一个复选框.我尝试添加<ice:selectManyCheckbox>
,但是它显示一个空列,并且没有出现该复选框.
I have a <ice:dataTable>
and I want to add a checkbox to each row. I tried to add a <ice:selectManyCheckbox>
, but it shows an empty column and the checkboxes doesn't appear.
<ice:selectManyCheckbox id="customTransChbx" partialSubmit="true">
<f:selectItems id="SlctLangItms" value="#{employee.s}" />
</ice:selectManyCheckbox>
<ice:dataTable id="employeedatatable" value="#{employee.model}" var="emp" rows="5">
<ice:column>
<ice:checkbox for="customTransChbx" index="#{emp.id}" rendered="true" />
</ice:column>
</ice:dataTable>
如何通过<ice:dataTable>
中的复选框选择多行?
How can I select multiple rows by checkboxes in a <ice:dataTable>
?
更新:我还尝试了<ice:selectBooleanCheckbox>
和Map
:
public class Employee {
private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
public void preRender(ComponentSystemEvent event) throws Exception {
List<Employee> list = employeeService.getEmployees();
for (Employee employee : list)
checked.put(employee.getId(), false);
}
}
使用
<ice:dataTable id="employeedatatable" value="#{employee.model}" var="emp" rows="5">
<ice:column>
<ice:selectBooleanCheckbox value="#{employee.checked[emp.id]}" />
</ice:column>
</ice:dataTable>
当尝试以操作方法获取检查列表时,映射中的所有值均为false
,甚至包括选定的值.为什么检查后的值没有放在Map
中?
When trying to get the checked list in an action method, all the values in the map are false
, even the selected ones. Why are the checked values not put in the Map
?
UPDATE2:我尝试使用旧的普通html方式,如下所示:
UPDATE2: i tried the old plain html way, as follows:
-
将复选框定义为输入:
defining the checkbox as input:
<input type="checkbox" name="toDelete" value="#{emp.id}" />
在后备bean方法中获取检查值,如下所示:
getting the checked values in the backing bean method as follows:
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
String[] checkedValues = request.getParameterValues("toDelete");
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
String[] checkedValues = request.getParameterValues("toDelete");
问题是checkedValues数组始终为空吗?
problem is that the checkedValues array is always null ?
推荐答案
请确保数据表和按钮的表单相同. strong>.
please make sure that the datatable and the button are in the same form.
这篇关于如何将ice:selectManyCheckbox添加到ice:dataTable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!