0

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 ?

abdelhady
  • 560
  • 5
  • 10
  • 23
  • Seems like it should work. Perhaps it's a bug or limitation in IceFaces. You can always try a combination of `` and a `HashMap`. See also http://stackoverflow.com/questions/2524514/how-to-use-jsfs-hselectbooleancheckbox-with-hdatatable-to-create-one-object-p/2524832#2524832 – BalusC Nov 23 '11 at 11:39
  • i tried it and it doesn't work too, please see the question update. – abdelhady Nov 23 '11 at 13:27
  • You actually don't need to prefill the list at all. But that shouldn't be the problem. Sorry, I don't know. It'll be something specific to IceFaces. – BalusC Nov 23 '11 at 13:52
  • even if i changed all the above code to use JSF core not icefaces, still getting same behavior. – abdelhady Nov 23 '11 at 14:35
  • Then your data preserving logic is not correct. You need to ensure that `#{employee.model}` is properly preserved for the request of processing the form submit. Easiest is to put the bean in the view scope. – BalusC Nov 23 '11 at 14:37
  • i already tried view scope, and still getting same behavior. – abdelhady Nov 23 '11 at 16:50
  • i tried another way, question is updated, please advise. – abdelhady Nov 23 '11 at 16:53

1 Answers1

0

please make sure that the datatable and the button are in the same form.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498