0

我有一个 xhtml 文件和一个托管 bean,我在其中定义Map<Integer, Boolean> 了在视图层中使用它来支持selectBooleanCeckbox嵌套在分页中的dataTable.

Map对于所有显示的Cliente内容都很常见,我真正需要的是 Map<Cliente, Map<Integer, Boolean>>每个客户都有其对应的地图。

实际问题是NullPointerException当我移动到dataTable.

如何Map<Cliente, Map<Integer, Boolean>>在视图层中迭代 a。

这是带有简单的xhtml文件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>

这是bean代码,

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();
}

该行selectedIds.get(dataItem.getId()).booleanValue()抛出该异常。

我该怎么做?

4

0 回答 0