3 Replies Latest reply on Nov 11, 2008 5:17 AM by swathi samala

    How to delete a row in datatable using check box

    swathi samala Newbie

      Hi everbody,
      Can any body tell me how to delete a row in data table using checkbox.
      i.e for each and every row at the begining there will be a check box. If we select that check box and click on delete it should get deleted.... I wrote an xhtml file, an entity and an action class but, but the remove method is not getting mapped to checkbox....
      here is my xhtml code any body please help me to solve it



      <rich:dataTable style="width:100%;" id="contentDetails"
                                    value="#{contentDetails.resultList}" var="content"
                                    rendered="#{not empty contentDetails.resultList}"
                                    rowClasses="#{tableLnF.getRowSettings(skinBean.skin)}"
                                    headerClass="#{tableLnF.getHeaderSettings(skinBean.skin)}"
                                    rows="10" columnClasses="formFont2">
                                    <rich:column align="left" colspan="1">
                                        <f:facet name="header"><h:outputText style="text-align:left;" value="Select"></h:outputText></f:facet>
                                                  <h:selectManyCheckbox value="#{contentListHome.contId}" id="checkbox" required="true">
                                                       <f:selectItem itemValue="#{content.contId}" itemLabel="#{content.contId}"/>
                                               </h:selectManyCheckbox>
                                    </rich:column>


        • 1. Re: How to delete a row in datatable using check box
          kaan acar Newbie

          You can use ajax support if you are using richfaces.


          < h:selectManyCheckbox value="#{contentListHome.contId}" id="checkbox" required="true">
                <f:selectItem itemValue="#{content.contId}" itemLabel="#{content.contId}"/>
                <a4j:support event="onchange" ajaxSingle="true" action="#{bean.delete}"/>
          </h:selectManyCheckbox>



          • 2. Re: How to delete a row in datatable using check box
            swathi samala Newbie

            Thank you Kaan Acar.... I have tried that also but am getting conversation error....


            09:33:36,015 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
            sourceId=contentManagementForm:myForm:contentDetails:1:checkbox[severity=(ERROR 2), summary=(Conversion Error setting value '21250' for '#{contentListHome.contId}'. ), detail=(Conversion Error setting value '21250' for '#{contentListHome.contId}'. )]
            09:33:36,515 INFO  [STDOUT] *******selected category id  is:2
            09:33:36,531 INFO  [STDOUT] *******selected category id  is:2
            09:33:36,765 INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
            sourceId=contentManagementForm:myForm:contentDetails:1:checkbox[severity=(ERROR 2), summary=(Conversion Error setting value '21250' for '#{contentListHome.contId}'. ), detail=(Conversion Error setting value '21250' for '#{contentListHome.contId}'. )]
            sourceId=contentManagementForm:myForm:contentDetails:2:checkbox[severity=(ERROR 2), summary=(Conversion Error setting value '' for '#{contentListHome.contId}'. ), detail=(Conversion Error setting value '' for '#{contentListHome.contId}'. )]
            sourceId=contentManagementForm:myForm:contentDetails:3:checkbox[severity=(ERROR 2), summary=(Conversion Error setting value '' for '#{contentListHome.contId}'. ), detail=(Conversion Error setting value '' for '#{contentListHome.contId}'. )]
            sourceId=contentManagementForm:myForm:contentDetails:0:checkbox[severity=(ERROR 2), summary=(Conversion Error setting value '' for '#{contentListHome.contId}'. ), detail=(Conversion Error setting value '' for '#{contentListHome.contId}'. )]
            


            Action class


            package com.manam.mewe.agile.pms.admin;
            
            import java.io.Serializable;
            import java.util.ArrayList;
            import java.util.Calendar;
            import java.util.HashSet;
            import java.util.List;
            
            import javax.faces.context.FacesContext;
            import javax.faces.model.SelectItem;
            import javax.persistence.EntityManager;
            import javax.servlet.http.HttpServletRequest;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Begin;
            import org.jboss.seam.annotations.End;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.annotations.datamodel.DataModel;
            import org.jboss.seam.annotations.web.RequestParameter;
            import org.jboss.seam.faces.FacesMessages;
            import org.jboss.seam.faces.Renderer;
            import org.jboss.seam.framework.EntityHome;
            import org.jboss.seam.security.Identity;
            
            import sun.security.jca.GetInstance;
            
            
            import com.manam.mewe.agile.pms.admin.ContentList;
            import com.manam.mewe.agile.pms.audittrial.AuditTrialConstants;
            import com.manam.mewe.agile.pms.audittrial.AuditTrialController;
            import com.manam.mewe.agile.pms.entity.admin.Content;
            import com.manam.mewe.agile.pms.entity.audittrials.AuditTrial;
            
            @Name("contentListHome")
            public class ContentListHome extends EntityHome<Content> implements     Serializable {
                    
                    
                 @RequestParameter("contId")
                 Long contId;
                
                 
            //     @In(scope = ScopeType.CONVERSATION, required = false)
                 @RequestParameter("categoryId")
                 Long categoryId;
                 
                 //@In(scope = ScopeType.CONVERSATION, required = false)
                 @RequestParameter("categoryName")
                 String catName;
            
                 @In(scope=ScopeType.CONVERSATION, required=false)
                 @Out(scope=ScopeType.CONVERSATION, required=false)
                 Long categoryIdConversation;
                 
                 @In(scope=ScopeType.CONVERSATION, required=false)
                 @Out(scope=ScopeType.CONVERSATION, required=false)
                 String categoryNameConversation;
            
                 @In
                 Identity identity;
                 
                 @In(create=true) Content content;
                 @In
                 private FacesMessages facesMessages;
                 @In(create = true)
                 private Renderer renderer;
                 @In
                 EntityManager entityManager;
                 ArrayList categoryList=new ArrayList();
                 String authorizer;
                 String displayComponent;
                 public SelectItem currentItem;
                 @Override
                 @Begin(join = true)
                 public void create() {
                      
                      System.out.println("***is managed"+this.isManaged());
                      super.create();
                           
                 }
                 
                 @Override
                 @End
                 public String persist() {
                      Calendar cal = java.util.GregorianCalendar.getInstance() ;
                      List result=(List) entityManager.createQuery("from Content content where value=:currentValue")
                      .setParameter("currentValue",content.getValue()).getResultList();
                      if ((result == null) || (result.size() == 0)) {
                           System.out.println("****categoryIdConversation is"+categoryIdConversation);
                           
                      getInstance().setContentCategoryID(getCategoryIdConversation());
                      getInstance().setCreatedBy(identity.getUsername());
                      getInstance().setCreatedOn(cal.getTime());
                      
                      System.out.println("(BEFORE PERSIST)id is:"+getInstance().getContentCategoryID());
            
                      super.persist();
                      
                      return "done";
                      }
                      else{
                           facesMessages.add(
                           "content : #{content.value} already existed");
                      return null;
                      }
                 }
                 
                 @Override
                 @End
                 public String update() {
            
                      try {
                           super.update();
                      } catch (Exception e) {
                           return null;
                      }
            
                      return "done";
            
                 }
                 @Override
                 public Object getId() {
                      if (id == null) {
                           return super.getId();
                      } else {
                           return id;
                      }
                 }
            
                 @Override
                 @End
                 public String remove() {
                      try {
                           System.out.println("*********in remove*********");
                           getInstance().setContId(contId);
                           System.out.println("********* Deleted *************");
                           super.remove();
                      } catch (Exception e) {
                           return null;
                      }
            
                      return "done";
                 }
            
                 public Long getCategoryIdConversation() {
            
                      System.out
                                .println("***categoryIdConversation(in ContentListHome.java) is:"
                                          + categoryIdConversation);
                      return categoryIdConversation;
                 }
            
                 public void setCategoryIdConversation(Long categoryIdConversation) {
                      this.categoryIdConversation = categoryId;
                 }
            
                 
            
                 public Long getCategoryId() {
                      return categoryId;
                 }
            
                 public void setCategoryId(Long categoryId) {
                      this.categoryId = categoryId;
                 }
            
                 
                 public Identity getIdentity() {
                      return identity;
                 }
            
                 public void setIdentity(Identity identity) {
                      this.identity = identity;
                 }
            
                 public FacesMessages getFacesMessages() {
                      return facesMessages;
                 }
            
                 public void setFacesMessages(FacesMessages facesMessages) {
                      this.facesMessages = facesMessages;
                 }
            
                 public Renderer getRenderer() {
                      return renderer;
                 }
            
                 public void setRenderer(Renderer renderer) {
                      this.renderer = renderer;
                 }
            
                 public String getCatName() {
                      return catName;
                 }
            
                 public void setCatName(String catName) {
                      this.catName = catName;
                 }
            
                 public String getCategoryNameConversation() {
                      return categoryNameConversation;
                 }
            
                 public void setCategoryNameConversation(String categoryNameConversation) {
                      this.categoryNameConversation = categoryNameConversation;
                 }
            
                 public void setId(Long id) {
                      this.id = id;
                 }
            
                 
                 public ArrayList getCategoryList() {
                      return categoryList;
                 }
                 public void setCategoryList(ArrayList categoryList) {
                      this.categoryList = categoryList;
                 }
                 public String getAuthorizer() {
                      return authorizer;
                 }
                 public void setAuthorizer(String authorizer) {
                      this.authorizer = authorizer;
                 }
                 public String getDisplayComponent() {
                      return displayComponent;
                 }
                 public void setDisplayComponent(String displayComponent) {
                      this.displayComponent = displayComponent;
                 }
                 public SelectItem getCurrentItem() {
                      return currentItem;
                 }
                 public void setCurrentItem(SelectItem currentItem) {
                      this.currentItem = currentItem;
                 }
                 public Long getContId() {
                      return contId;
                 }
                 public void setContId(Long contId) {
                      this.contId = contId;
                 }
                 public ArrayList getContentsList() {
                      return contentsList;
                 }
                 public void setContentsList(ArrayList contentsList) {
                      this.contentsList = contentsList;
                 }
                 public ArrayList<Content> getTempList() {
                      return tempList;
                 }
                 public void setTempList(ArrayList<Content> tempList) {
                      this.tempList = tempList;
                 }
                 public Content getContent() {
                      return content;
                 }
                 public void setContent(Content content) {
                      this.content = content;
                 }
                 
                 
            }
            


            Entitybean


            package com.manam.mewe.agile.pms.entity.admin;
            
            import java.io.Serializable;
            
            
            import java.io.Serializable;
            import java.util.Date;
            import java.util.Set;
            
            import javax.persistence.CascadeType;
            import javax.persistence.Column;
            import javax.persistence.Entity;
            import javax.persistence.GeneratedValue;
            import javax.persistence.GenerationType;
            import javax.persistence.Id;
            import javax.persistence.JoinColumn;
            import javax.persistence.JoinTable;
            import javax.persistence.ManyToOne;
            import javax.persistence.OneToOne;
            import javax.persistence.SequenceGenerator;
            import javax.persistence.Transient;
            import javax.persistence.UniqueConstraint;
            import javax.persistence.Version;
            
            import org.hibernate.validator.Length;
            import org.hibernate.validator.NotNull;
            import org.jboss.seam.annotations.Name;
            
            @Name("content")
            @Entity
            
            public class Content implements Serializable {
                 
                 
                 private Long contId;
                 private String value;
                 private String createdBy;
                 private String updatedBy;
                 private Date createdOn;
                 private Date updatedOn;
                 //dummy variable
                 private Long contentCategoryID;
                 
                 private ContentCategory contentcategory=null;
                 @Id
                 @GeneratedValue(strategy=GenerationType.SEQUENCE)
                 public Long getContId() {
                      return contId;
                 }
            
                 public void setContId(Long contId) {
                      this.contId = contId;
                 }
            
                 
                 public String getValue() {
                      return value;
                 }
            
                 public void setValue(String value) {
                      this.value = value;
                 }
            
                 @ManyToOne(cascade=CascadeType.PERSIST)
                 public ContentCategory getContentcategory() {
                      return contentcategory;
                 }
            
                 public void setContentcategory(ContentCategory ntcatcontentcategoryegory) {
                      this.contentcategory = ntcatcontentcategoryegory;
                 }
            
                 /*
                  * dummy variable getter&setr methods
                  */
                 public Long getContentCategoryID() {
                      return contentCategoryID;
                 }
            
                 public void setContentCategoryID(Long contentCategoryID) {
                      this.contentCategoryID = contentCategoryID;
                 }
            
                 public String getCreatedBy() {
                      return createdBy;
                 }
            
                 public void setCreatedBy(String createdBy) {
                      this.createdBy = createdBy;
                 }
            
                 public String getUpdatedBy() {
                      return updatedBy;
                 }
            
                 public void setUpdatedBy(String updatedBy) {
                      this.updatedBy = updatedBy;
                 }
            
                 public Date getCreatedOn() {
                      return createdOn;
                 }
            
                 public void setCreatedOn(Date createdOn) {
                      this.createdOn = createdOn;
                 }
            
                 public Date getUpdatedOn() {
                      return updatedOn;
                 }
            
                 public void setUpdatedOn(Date updatedOn) {
                      this.updatedOn = updatedOn;
                 }
            
            }
            




            • 3. Re: How to delete a row in datatable using check box
              swathi samala Newbie

              EntityQuery class


              package com.manam.mewe.agile.pms.admin;
              
              import java.io.Serializable;
              import java.util.ArrayList;
              
              import javax.persistence.EntityManager;
              
              import org.jboss.seam.ScopeType;
              import org.jboss.seam.annotations.In;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.framework.EntityController;
              import org.jboss.seam.framework.EntityQuery;
              
              import com.manam.mewe.agile.pms.entity.admin.Content;
              import com.manam.mewe.agile.pms.entity.admin.ContentCategory;
              
              @Name("contentDetails")
              public class ContentDetails extends EntityQuery<Content> implements
                        Serializable {
              
                   @In(scope = ScopeType.CONVERSATION, required = false)
                   Long categoryIdConversation;
              
                   
                   @Override
                   public String getEjbql() {
              
                        System.out.println("*******selected category id  is:"
                                  + categoryIdConversation);
              
                        return "select co from Content co where co.contentCategoryID in (select cmg.id from contentCategory cmg where cmg.id="
                                  + categoryIdConversation + ")";
                   }     
              }