2 Replies Latest reply on Apr 28, 2010 7:17 AM by Venkatesh K

    How to get multiple selected rows using checkbox

    Venkatesh K Newbie
      I am facing the problem with check box it's giving me null
      <rich:dataTable id="itDamageDetailTable"
                                         var="_damageDetail" selectionMode="single" width="950px" selectedClass="selection"
                                          value="#{itShipDamageDetails}" rendered="#{itShipDamageDetails.rowCount > 0}"
                                         headerClass="removeheader">
                                         
                          <rich:column id="check">
                               <h:selectBooleanCheckbox id="Checkbox" value="#{shipmentDamage.detailSelection[_damageDetail]}"/>
                      </rich:column>
                          
                          <rich:column id="itShipmentDetail" width="120px" headerClass="head"
                                          footerClass="removefooter" label="#{messages['com.infyz.toms.properties.Shipment_number']}">
                               <f:facet name="header">
                                  <h:outputText styleClass="headerText" value="#{messages['com.infyz.toms.properties.Shipment_number']}" />
                               </f:facet>
                               <h:outputText value="#{_damageDetail.itShipmentDetail.itShipmentOrder.shipmentNumber}" />
                          </rich:column>


      and my seesion is
      @Stateful
      @Name("shipmentDamage") 
      @Scope(ScopeType.SESSION)
      public class ShipmentDamageAction implements ShipmentDamageInterface {

      private List<ItDamageDetails> damageDetailsList=new ArrayList<ItDamageDetails>(0);
           
                 @DataModel("itShipDamageDetails")
                private List<ItDamageDetails> itShipDamageDetails;

                @Factory("itShipDamageDetails")
               @Observer("itShipDamageDetailConfirmed")
                public void getItShipDamageDetails() {
                     try{
                          if(shipDetail !=null){
                          itShipDamageDetails= em.createQuery("from ItDamageDetails as VP  where VP.itShipmentDetail.shipmentDetailId=:damageDetails")
                       .setParameter("damageDetails", shipDetail.getShipmentDetailId()).getResultList();
                          itShipDamageDetails.addAll(damageDetailsList);
                          }
                     }
                     catch (java.lang.NullPointerException e) {}
                }

      private Map<ItDamageDetails,Boolean> detailSelection  = new HashMap<ItDamageDetails,Boolean>();
                
                
                //@SuppressWarnings("unchecked")
               public Map<ItDamageDetails,Boolean> getDetailSelection() {
                   return detailSelection;
               }
      and i am using a4J:commandButton for cancel which call the action to delete selected rows from the table
      <a4j:commandButton id="cancelHold" action="#{shipmentDamage.cancel}" reRender="itDamageDetailTable" immediate="true"
                            value="#{messages['com.infyz.toms.label.button.tooltip.Cancel']}"/>


      action is

      @End
           public String cancel(){
                List<ItDamageDetails> temp = new ArrayList<ItDamageDetails>();
                for (ItDamageDetails line: itShipDamageDetails) {
                     Boolean select = detailSelection.get(line);
                     log.info(".................................................................................."+select);
                     if(select == null || !select)
                     {
                          temp.add(line);
                     }
              }
                itShipDamageDetails.clear();
                itShipDamageDetails.addAll(temp);
                detailSelection = new HashMap<ItDamageDetails,Boolean>();
                return "/operations/itShipmentDamageDetail.xhtml";
           }

      here when i am displaying the 'selected' value it's always displaying the null
      please help........... me