Map<Integer, Boolean> for selectBooleanCeckbox
pepelara Nov 27, 2012 5:09 PMI have a xhtml file and a managed bean where I have defined Map<Integer, Boolean>
to use it in the view layer to support a selectBooleanCeckbox nested inside a dataTable.
This Map is common for all the displayed Cliente and what I really need is a
Map<Cliente, Map<Integer, Boolean>> where every Cliente has its corresponding
Map<Integer, Boolean>.
The actual problem is the Map throws a NullPointerException when I move to another page
in the dataTable.
I do not know the way to iterate a Map<Cliente, Map<Integer, Boolean>> in the view layer.
Here is the xhtml file with the simple Map,
<c:forEach items="#{adminCarritoBean.clientes}" var="map"> <c:set value="#{0}" var="cont"/> <c:forEach items="#{map.keySet}" var="cliente"> <rich:dataTable value="#{map.get(cliente)}" var="carrito" iterationStatusVar="it" rows="5"> <h:column> <f:facet name="header"> <h:outputText value="Select" /> </f:facet> <h:selectBooleanCheckbox value="#{adminCarritoBean.selectedIds[carrito.id]}" /> </h:column> ------------------ ----------------- <f:facet name="footer"> <rich:dataScroller page="#{adminCarritoBean.page[cont]}" /> </f:facet> </rich:dataTable> <c:set value="#{cont + 1}" var="cont"/> </c:forEach> </c:forEach>
and here is the bean code,
private Map<Integer, Boolean> selectedIds; private List<Carrito> selectedDataList; private List<Map<Cliente, List<Carrito>>> clientes; public void eliminar() { selectedDataList = new ArrayList<Carrito>(); for (Map<Cliente, List<Carrito>> cliente: clientes) { Set<Cliente> keys = cliente.keySet(); for(Iterator<Cliente> it = keys.iterator(); it.hasNext();) { Cliente clte = it.next(); List<Carrito> carritos = cliente.get(clte); for(Carrito dataItem: carritos) { if(selectedIds.get(dataItem.getId()).booleanValue()) { selectedDataList.add(dataItem); selectedIds.remove(dataItem.getId()); // Reset. } } } } for(Carrito crto: selectedDataList) { carritoDAO.eliminar(crto); } selectedIds = new HashMap<Integer, Boolean>(); loadListClientes(); }
The line selectedIds.get(dataItem.getId()).booleanValue() throws that exception.
How can I do it?
Any idea?
Best regards,
Jose