0 Replies Latest reply on May 8, 2011 9:36 AM by Umesh Annegirikar

    problem in deleting the row using h:selectManyCheckbox

    Umesh Annegirikar Newbie

      hello friends

         I am using richfaces 4.0 for the portal development .In our web application we have created one dataTable which contains the customers  we use multiple selections checkboxes for selecting the  our requirement is that whenever we click on the checkboxes the values are deleted from the database table & at the same time but whenever we click on the multiple checkboxes we dont get selectionIDs so that we can delete the customers from the customer in the dataTable

      our code :

       

      customerList.xhtml

      <rich:dataTable id="customer_list" value="#{manageBean.customers}" var="customer" height="200px" style="width : 100%;">

                                      <rich:column style="border-color: #FBEFEF; column-color: #EFFBF5">

                  <f:facet name="header">

                      <h:selectBooleanCheckbox value=" " />

                  </f:facet>

       

       

                  <h:selectManyCheckbox id="cust" value="#{manageBean.customers}" disabled="false" >

                      <f:selectItem value="#{cust.id}" />

                      <f:selectItems value="#{manageBean.selectableItems}" />

               </h:selectManyCheckbox>

       

                  <!--<h:selectBooleanCheckbox value="#{customer.selected}" />-->

       

              </rich:column>

              <rich:column style="border-color: #FBEFEF;">

                 <f:facet name="header">

                     <h:outputText value="Id" />

                 </f:facet>

                 <h:outputText value="#{customer.id}" />

             </rich:column>

       

       

            <rich:column style="border-color: #FBEFEF">

                 <f:facet name="header">

                     <h:outputText value="Sector Activity" />

                 </f:facet>

                 <h:outputText value="#{customer.sectorActivity}" />

             </rich:column>

        </rich:dataTable>

       

        <a4j:commandButton value="Delete" action="#{manageBean.deleteCustomer}" immediate="true">

          <f:param name="VALIDATE" value="false" />

        </a4j:commandButton>

       

      manageBean.java--bean class

       

      @ManagedBean

      @SessionScoped

      public class ManageBean extends SpringBeanAutowiringSupport

      {

              private List<SelectItem>    selectableItems;

       

       

          public String deleteCustomer()

          {

              System.out.println("Inside delete customer method.");

              try

              {

                  if(selectableItems == null)

                  {

                      System.out.println("selectableItems is null.");

                  }

                  else

                  {

                      System.out.println("selectableItems not null.");

                  }

                  List<Customer> selectedItems = new ArrayList<Customer>();

       

                  System.out.println("before delete opration. selectedItems size : " + selectedItems.size());

                  if (selectedItems.size() > 0)

                  {

                      for (int i = 0; i < selectedItems.size(); i++)

                      {

                          Customer customer = selectedItems.get(i);

                          daoService.delete(customer);

                          System.out.println("Customer deleted  successfully.");

                      }

                  }

                  System.out.println("after delete opration.");

                  if (currentUser != null)

                  {

                      System.out.println("Project is not null");

       

                      customers = daoService.getCustomersByUserId(currentUser.getId());

                      if (customers != null && customers.size() > 0)

                      {

                          System.out.println("customerList size : " + customers.size());

                          this.listStatus = true;

                      }

                      else

                      {

                          this.listStatus = false;

                      }

                  }

              }

              catch (Exception ex)

              {

                  System.out.println("Exception" + ex.getMessage());

              }

              System.out.print("Customer list returned successfully. ");

       

              this.displayLogin = "none";

              this.displayLogout = "";

              return "customerList";

          }

       

          public List<SelectItem> getSelectableItems()

          {

              return selectableItems;

          }

       

          public void setSelectableItems(List<SelectItem> selectableItems)

          {

              this.selectableItems = selectableItems;

          }

       

       

      }

       

       

      Customer.java:

       

      package com.bitongline.abc.dao.domain;

       

      import static javax.persistence.GenerationType.IDENTITY;

       

      import java.util.HashSet;

      import java.util.Set;

       

      import javax.persistence.CascadeType;

      import javax.persistence.Column;

      import javax.persistence.Entity;

      import javax.persistence.FetchType;

      import javax.persistence.GeneratedValue;

      import javax.persistence.Id;

      import javax.persistence.JoinColumn;

      import javax.persistence.ManyToOne;

      import javax.persistence.OneToMany;

      import javax.persistence.Table;

       

      /**

      * Customer entity. @author MyEclipse Persistence Tools

      */

      @Entity

      @Table(name = "customer", catalog = "bitongline_abc")

      public class Customer implements java.io.Serializable

      {

       

          // Fields

       

          private Integer    id;

          private Project    project;

          private String    company;

          private String    city;

          private String    zip;

          private String    country;

          private String    customerSince;

          private String    sectorActivity;

          private User    user;

          private Set<CandidateCustomer>    candidateCustomers    = new HashSet<CandidateCustomer>(0);

       

          // Constructors

       

          /** default constructor */

          public Customer()

          {

          }

       

          /** minimal constructor */

          public Customer(Project project)

          {

              this.project = project;

          }

       

          /** full constructor */

       

          public Customer(Project project, String company, String city, String zip, String country, String customerSince, String sectorActivity, Set<CandidateCustomer> candidateCustomers)

          {

              this.project = project;

              this.company = company;

              this.city = city;

              this.zip = zip;

              this.country = country;

              this.customerSince = customerSince;

              this.sectorActivity = sectorActivity;

              this.candidateCustomers = candidateCustomers;

          }

       

          public Customer(Project project, String company, String city, String zip, String country, String customerSince, String sectorActivity)

          {

              this.project = project;

              this.company = company;

              this.city = city;

              this.zip = zip;

              this.country = country;

              this.customerSince = customerSince;

              this.sectorActivity = sectorActivity;

          }

       

          // Property accessors

          @Id

          @GeneratedValue(strategy = IDENTITY)

          @Column(name = "id", unique = true, nullable = false)

          public Integer getId()

          {

              return this.id;

          }

       

          public void setId(Integer id)

          {

              this.id = id;

          }

       

          @ManyToOne(fetch = FetchType.LAZY)

          @JoinColumn(name = "project_id", nullable = false)

          public Project getProject()

          {

              return this.project;

          }

       

          public void setProject(Project project)

          {

              this.project = project;

          }

       

          @Column(name = "company")

          public String getCompany()

          {

              return this.company;

          }

       

          public void setCompany(String company)

          {

              this.company = company;

          }

       

          @Column(name = "city")

          public String getCity()

          {

              return this.city;

          }

       

          public void setCity(String city)

          {

              this.city = city;

          }

       

          @Column(name = "zip")

          public String getZip()

          {

              return this.zip;

          }

       

          public void setZip(String zip)

          {

              this.zip = zip;

          }

       

          @Column(name = "country")

          public String getCountry()

          {

              return this.country;

          }

       

          public void setCountry(String country)

          {

              this.country = country;

          }

       

          @Column(name = "customer_since")

          public String getCustomerSince()

          {

              return this.customerSince;

          }

       

          public void setCustomerSince(String customerSince)

          {

              this.customerSince = customerSince;

          }

       

          @Column(name = "sector_activity")

          public String getSectorActivity()

          {

              return this.sectorActivity;

          }

       

          public void setSectorActivity(String sectorActivity)

          {

              this.sectorActivity = sectorActivity;

          }

       

          @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customer")

          public Set<CandidateCustomer> getCandidateCustomers()

          {

              return this.candidateCustomers;

          }

       

          public void setCandidateCustomers(Set<CandidateCustomer> candidateCustomers)

          {

              this.candidateCustomers = candidateCustomers;

          }

       

          @ManyToOne(fetch = FetchType.LAZY)

          @JoinColumn(name = "user_id", nullable = false)

          public User getUser()

          {

              return user;

          }

       

          public void setUser(User user)

          {

              this.user = user;

          }

      }

       

       

      So please give me the solution we are stuck to this problem since last two days.

       

      Thanking you...

       

      Regards

      Umesh