How to add ice:selectManyCheckbox to a ice:dataTable?

橙三吉。 提交于 2019-12-25 02:25:00

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!