1 2 Previous Next 19 Replies Latest reply on Sep 9, 2009 11:35 AM by seamkaruna

    how to use selectmanycheckbox

    seamkaruna

      hi there,


      I'm new to seam so plz help me how to use selectmanycheck with database data (store and retrieve values).


      thanks,

        • 1. Re: how to use selectmanycheckbox

          Hi, this is an example


          <s:decorate id="orderTypeField" template="layout/edit.xhtml" >
                          <ui:define name="label">#{messages['Order.type']}</ui:define>
                              <h:selectManyCheckbox id="manyCheckbox" 
                                              label="#{messages['Order.type']}"
                                               value="#{myBean.orderTypes}"
                                               required="true">
                                               <f:converter converterId="project.myTypeConverter"/>
                                  <f:selectItems value="#{factoryItems}" var="orderType"
                                      label="#{orderType.description}"/>
                              </h:selectManyCheckbox >
                          </s:decorate>
          



          factoryItems is a factory component that has a simple HQL query to database that gets all elements to be displayed.
          The use of convertes depends on what you are using.


          You may find more info about this tag in this link


          • 2. Re: how to use selectmanycheckbox
            seamkaruna

            hi jaime,


              thanks for ur reply but i'm very new to this framework so please post any simple sample codes with backingbeans(step by step explination) and my prob is to store value in the database. plz post me some useful codes.


            thanks,

            • 3. Re: how to use selectmanycheckbox

              I´m so sorry but I´m very busy right now to provide you with a step by step explanation. I´ll do it later if I´ve time
              Hope this links: link and link 2
              would be useful for you.
              actories are explaind in seam reference and there you may find some explained examples.

              • 4. Re: how to use selectmanycheckbox
                seamkaruna
                Hi thanks for your reply,

                but i'm getting error while running my code. so i posting my code here plz find where i am going wrong. plz this is very urgent.

                XHTML File.


                <h:selectManyCheckbox id="rights"
                value="#{accessrightsHome.instance.id.accesscontrol}"
                layout="lineDirection" border="1">
                <f:selectItem id="item1" itemLabel="Read" itemValue="1"/>
                <f:selectItem id="item2" itemLabel="Write" itemValue="2"/>
                <f:selectItem id="item3" itemLabel="Delete" itemValue="3"/>
                </h:selectManyCheckbox>


                Backing Bean

                public class AccessrightsId  implements java.io.Serializable {


                     private String deptname;
                     private String rolename;
                     private String[] accesscontrol;
                    
                    public AccessrightsId() {
                    }

                    public AccessrightsId(String deptname, String rolename, String[] accesscontrol) {
                       this.deptname = deptname;
                       this.rolename = rolename;
                       this.accesscontrol = accesscontrol;
                    }
                  
                    @Column(name="deptname", length=50)
                    @Length(max=50)
                    public String getDeptname() {
                        return this.deptname;
                    }
                   
                    public void setDeptname(String deptname) {
                        this.deptname = deptname;
                    }


                    @Column(name="rolename", length=50)
                    @Length(max=50)
                    public String getRolename() {
                        return this.rolename;
                    }
                   
                    public void setRolename(String rolename) {
                        this.rolename = rolename;
                    }


                    @Column(name="accesscontrol", length=50)
                    @Length(max=50)
                    public String[] getAccesscontrol() {
                        return this.accesscontrol;
                    }
                   
                    public void setAccesscontrol(String[] accesscontrol) {
                        this.accesscontrol = accesscontrol;
                    }



                public boolean equals(Object other) {
                         if ( (this == other ) ) return true;
                                 if ( (other == null ) ) return false;
                                 if ( !(other instanceof AccessrightsId) ) return false;
                                 AccessrightsId castOther = ( AccessrightsId ) other;
                        
                                 return ( (this.getDeptname()==castOther.getDeptname()) || ( this.getDeptname()!=null && castOther.getDeptname()!=null && this.getDeptname().equals(castOther.getDeptname()) ) )
                && ( (this.getRolename()==castOther.getRolename()) || ( this.getRolename()!=null && castOther.getRolename()!=null && this.getRolename().equals(castOther.getRolename()) ) )
                && ( (this.getAccesscontrol()==castOther.getAccesscontrol()) || ( this.getAccesscontrol()!=null && castOther.getAccesscontrol()!=null && this.getAccesscontrol().equals(castOther.getAccesscontrol()) ) );
                   }
                  
                   public int hashCode() {
                         int result = 17;
                        
                         result = 37 * result + ( getDeptname() == null ? 0 : this.getDeptname().hashCode() );
                         result = 37 * result + ( getRolename() == null ? 0 : this.getRolename().hashCode() );
                         result = 37 * result + ( getAccesscontrol() == null ? 0 : this.getAccesscontrol().hashCode() );
                         return result;
                   }  
                }

                plz help me and thanks in advance.
                • 5. Re: how to use selectmanycheckbox
                  cash1981

                  If I where you I would use a List<String accesscontrol;
                  Your error is


                  <h:selectManyCheckbox id="rights"
                  value="#{accessrightsHome.instance.id.accesscontrol}"



                  Should be



                  <h:selectManyCheckbox id="rights"
                  value="#{accessrightsHome.instance.accesscontrol}"



                  • 6. Re: how to use selectmanycheckbox
                    seamkaruna
                    hi servin,

                    when i use List<string> i'm getting this following error,

                    persistence.unit:unitName=acm.ear/acm.jar#acm -> org.hibernate.MappingException: Could not determine type for: java.util.List, at table: accessrights, for columns: [org.hibernate.mapping.Column(accesscontrol)]


                         at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:863)
                         at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:665)
                         at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:293)
                         at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
                         at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                         at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
                         at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
                         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
                         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
                         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
                         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                         at java.lang.Thread.run(Unknown Source)


                    and the accesscontrol field in database is varchar. I cannot use this <h:selectManyCheckbox id="rights"
                    value="#{accessrightsHome.instance.accesscontrol}" because it is the bean path for accesscontrol field(i didnt create primary key in that table), plz help me in this issue.

                    thanks
                    • 7. Re: how to use selectmanycheckbox

                      hi,
                      please paste the error you have trying it the original way.
                      By the way how have you defined accessrightsHome, paste attributes of the class at least.

                      • 8. Re: how to use selectmanycheckbox
                        seamkaruna
                        package com.acm.session;

                        import com.acm.entity.*;
                        import org.jboss.seam.annotations.Name;
                        import org.jboss.seam.framework.EntityHome;

                        @Name("accessrightsHome")
                        public class AccessrightsHome extends EntityHome<Accessrights>
                        {


                            public void setAccessrightsId(AccessrightsId id)
                            {
                                setId(id);
                            }

                            public AccessrightsId getAccessrightsId()
                            {
                                return (AccessrightsId) getId();
                            }

                            public AccessrightsHome()
                            {
                                setAccessrightsId( new AccessrightsId() );
                            }

                            @Override
                            public boolean isIdDefined()
                            {
                                if ( getAccessrightsId().getDeptname()==null || "".equals( getAccessrightsId().getDeptname() ) ) return false;
                                if ( getAccessrightsId().getRolename()==null || "".equals( getAccessrightsId().getRolename() ) ) return false;
                                if ( getAccessrightsId().getAccesscontrol()==null || "".equals( getAccessrightsId().getAccesscontrol() ) ) return false;
                                return true;
                            }

                            @Override
                            protected Accessrights createInstance()
                            {
                                Accessrights accessrights = new Accessrights();
                                accessrights.setId( new AccessrightsId() );
                                return accessrights;
                            }

                            public void wire()
                            {
                                getInstance();
                            }

                            public boolean isWired()
                            {
                                return true;
                            }

                            public Accessrights getDefinedInstance()
                            {
                                return isIdDefined() ? getInstance() : null;
                            }


                        }

                        • 9. Re: how to use selectmanycheckbox
                          seamkaruna
                          14:26:53,375 WARN  [HDScanner] Failed to process changes
                          org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):

                          *** CONTEXTS IN ERROR: Name -> Error

                          persistence.unit:unitName=acm.ear/acm.jar#acm -> org.hibernate.MappingException: Could not determine type for: java.util.List, at table: accessrights, for columns: [org.hibernate.mapping.Column(accesscontrol)]


                               at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:863)
                               at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:665)
                               at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:293)
                               at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
                               at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
                               at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
                               at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(Unknown Source)
                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(Unknown Source)
                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
                               at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
                               at java.lang.Thread.run(Unknown Source)

                          this is the error i am getting.
                          • 10. Re: how to use selectmanycheckbox

                            Hi, I provide you with an example



                                            <h:outputText value="TODOS"/>
                                                <h:selectManyCheckbox id="manyCheckbox" 
                                                                label="#{messages['Order.type']}"
                                                                 value="#{settlementInstructionDomesticBean.orderTypes}"
                                                                 class="selectStyle" 
                                                                 required="true">
                                                    <f:selectItems value="#{orderDomesticObjItems}" var="orderType"
                                                        label="#{orderType.description}"/>
                            />                            
                                                </h:selectManyCheckbox >
                            



                            and this is the factory:



                                @Factory("orderDomesticObjItems")
                                public List<SelectItem> getOrderDomesticObjItems() {
                            
                                    List<SelectItem> items = new ArrayList<SelectItem>();
                            
                                    for (OrderType st : this.getOrderByMarket()) {
                            
                                        SelectItem item = new SelectItem();
                                        item.setValue(st);
                                        item.setLabel(st.getDescription());
                            
                                        items.add(item);
                            
                                    }
                            
                                    return items;
                                }
                            
                                public List<OrderType> getOrderByMarket() {
                                    Query query=em.createQuery("FROM OrderType AS type");
                                    return query.getResultList();
                                }
                            
                            
                            





                            • 11. Re: how to use selectmanycheckbox
                              seamkaruna

                              hi,
                              after using above code i'm getting this following error,


                              java.lang.IllegalArgumentException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectMany(rights).  Found null.

                              • 12. Re: how to use selectmanycheckbox
                                seamkaruna
                                <h:selectManyCheckbox id="rights" value="#      {accessrightsHome.instance.id.accesscontrol}"
                                  layout="lineDirection" border="1">
                                  <f:selectItems value="#{rights}" label="#{rightstb.right}"/>
                                </h:selectManyCheckbox>


                                public List<Rightstb> getRightsparam() {
                                          String ejb = EJBQL;
                                          System.out.println(getEntityManager().createQuery(ejb).getResultList()
                                                    .size());
                                          return getEntityManager().createQuery(ejb).getResultList();
                                     }
                                     @Factory("Rights")
                                     public List<SelectItem> getRights()
                                     {
                                          List<SelectItem> results = new ArrayList<SelectItem>();
                                          for (Rightstb obj : this.getRightsparam())
                                          {
                                          SelectItem item = new SelectItem();
                                        item.setValue(obj.getRights());
                                        item.setLabel(obj.getRights());

                                        results.add(item);
                                          }
                                          return results;
                                     }
                                • 13. Re: how to use selectmanycheckbox
                                  seamkaruna

                                  hi my problem is in storing the selectmanycheckbox value into the database.

                                  • 14. Re: how to use selectmanycheckbox

                                    does your problem go on?
                                    Maybe it´s due to a type conversion feature. Try adding a converter:


                                      <s:convertEntity/>
                                    



                                    And if it doesn´t work with a custom converter


                                     <f:converter converterId="project.myTypeConverter"/>
                                    



                                    If you need an example of a custom converter let me know.



                                    1 2 Previous Next