问题
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>
How can I select multiple rows by checkboxes in a <ice:dataTable>
?
Update: I also tried <ice:selectBooleanCheckbox>
with a 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);
}
}
with
<ice:dataTable id="employeedatatable" value="#{employee.model}" var="emp" rows="5">
<ice:column>
<ice:selectBooleanCheckbox value="#{employee.checked[emp.id]}" />
</ice:column>
</ice:dataTable>
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: i tried the old plain html way, as follows:
defining the checkbox as input:
<input type="checkbox" name="toDelete" value="#{emp.id}" />
getting the checked values in the backing bean method as follows:
HttpServletRequest request = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
String[] checkedValues = request.getParameterValues("toDelete");
problem is that the checkedValues array is always null ?
回答1:
please make sure that the datatable and the button are in the same form.
来源:https://stackoverflow.com/questions/8230451/how-to-add-iceselectmanycheckbox-to-a-icedatatable