1 2 3 Previous Next 30 Replies Latest reply on Jan 9, 2011 3:25 PM by wadhah Go to original post
      • 15. Re: how to persist data from selectManyCheckbox
        lvdberg

        Hi,


        as proposed in my earlier answer. Check if the bean works correctly and is intercepted by Seam.


        A regular error would be that a specific attribute could be found on a named component. Instead it staes that it can't find the attribute on an Object.


        You should find the EJB in server configuration (check for it in the log file). Furthermore check in the log also if the Seam component is created with the specified name.


        Leo


        P.S. I see a lot of In annotations in your action bean, but I don't see any code how it gets there. Is this the only code you have or are more pieces missing ?

        • 16. Re: how to persist data from selectManyCheckbox
          wadhah

          Hi Leo
          In have just User and Role as entities and RegsiterBean as a bean.
          Leo please tell me how to check if the bean works correctly ?
          PS : i'm new in jee and seam


          Thank u 

          • 17. Re: how to persist data from selectManyCheckbox
            wadhah

            wadhah jebri wrote on Jan 05, 2011 15:59:


            Hi Leo
            I have just User and Role as entities and RegsiterBean as a bean.
            Leo please tell me how to check if the bean works correctly ?
            PS : i'm new in jee and seam

            Thank u 



            Click HELP for text formatting instructions. Then edit this text and check the preview.

            • 18. Re: how to persist data from selectManyCheckbox
              wadhah

              Leo van den Berg wrote on Jan 05, 2011 12:05:


              Hi,

              as proposed in my earlier answer. Check if the bean works correctly and is intercepted by Seam.

              A regular error would be that a specific attribute could be found on a named component. Instead it staes that it can't find the attribute on an Object.

              You should find the EJB in server configuration (check for it in the log file). Furthermore check in the log also if the Seam component is created with the specified name.

              Leo

              P.S. I see a lot of In annotations in your action bean, but I don't see any code how it gets there. Is this the only code you have or are more pieces missing ?


              Click HELP for text formatting instructions. Then edit this text and check the preview.


              Hi Leo,
              The problem is resolved i should add the getter and setter added in the bean on the interface ...

              • 19. Re: how to persist data from selectManyCheckbox
                wadhah

                Now i have an other error the name,username and password are stored on the database but the roles no.
                I have this error



                Caused by java.lang.IllegalStateException with message: "Could not commit transaction"



                • 20. Re: how to persist data from selectManyCheckbox
                  lvdberg

                  Hi,



                  The error is probably caused because you don't have entity conversion in your selectMany... Look at the s:convertEntity tag of Sesm, which is placed in side the tag. It will take care of converting the selected values to entities.



                  Leo



                  P.S: Seam is a set of components to deal with the complexity of J2EE etc. Before using it you should have a baic knowledge of the used technologies.


                  • 21. Re: how to persist data from selectManyCheckbox
                    wadhah

                    Leo van den Berg wrote on Jan 07, 2011 02:50:


                    Hi,


                    The error is probably caused because you don't have entity conversion in your selectMany... Look at the s:convertEntity tag of Sesm, which is placed in side the tag. It will take care of converting the selected values to entities.


                    Leo


                    P.S: Seam is a set of components to deal with the complexity of J2EE etc. Before using it you should have a baic knowledge of the used technologies.




                    Ok thank u for your answer ...
                    PS: i'm an engineering student we have seen and practice jee technologie since 3 months and now they gives us a project with seam :o 

                    • 22. Re: how to persist data from selectManyCheckbox
                      lvdberg

                      Hi,


                      As mentioned; Seam is pretty complex, but fortunately the documentation is really good and see if you can get a copy of the book Seam in Action from Manning. The book contains all the background information you need to learn how Seam works in cooperation with all the technologies. Als download the distribution. It contains all the examples/demo and they are very useful.


                      P.S. get used to it. In the real world you will see a lot of people (msot of them commercial) who think you can use new technologies in just 3 months.

                      • 23. Re: how to persist data from selectManyCheckbox
                        wadhah

                        Leo van den Berg wrote on Jan 07, 2011 04:51:


                        Hi,

                        As mentioned; Seam is pretty complex, but fortunately the documentation is really good and see if you can get a copy of the book Seam in Action from Manning. The book contains all the background information you need to learn how Seam works in cooperation with all the technologies. Als download the distribution. It contains all the examples/demo and they are very useful.

                        P.S. get used to it. In the real world you will see a lot of people (msot of them commercial) who think you can use new technologies in just 3 months.


                        I have a copy of Seam in action :)
                        I added this tag


                        <s:convertEntity/>



                        i had this error




                        Exception during request processing
                        Caused by javax.servlet.ServletException with message: For input string: admin



                        • 24. Re: how to persist data from selectManyCheckbox
                          lvdberg

                          Hi,


                          looking at your code again:


                          First: you need a query to retrieve all defined Role (s) Secondly the reulting list of Role's should be provided inside a selectManyListbox which give you the opportunity to select different roles at once.




                          <h:selectManyListbox value=#{Register.selectedRoles}>
                             <s:selectItem value="#{yourQuery.resultList}" var="_role" label=#{_role.rolename} />
                             <s:convertEntity/>
                          </h:selectManyListbox>



                          Peronally I prefer using one of the Richfaces components which makes doing the same a breeze.


                          Look there for more information about the different components.


                          Leo

                          • 25. Re: how to persist data from selectManyCheckbox
                            wadhah

                            Hi Leo
                            I made same modifications i added on the table Role two roles Admin and Agent and i added this function in the RegisterBean :



                            @Factory("selectedRoles")
                                 public List<Role> getSelectedRoles() {
                                      selectedRoles = em.createQuery("select rolename from Role").getResultList();
                                      return selectedRoles;
                                 }


                            this is the xhtml page : register.xhtml






                                 <h:selectManyCheckbox id="roles" value="#{user.roles}"
                                                          layout="pageDirection">
                                                          <s:selectItems var="role" itemLabel="#{role.rolename}"
                                                               value="#{Register.selectedRoles}" />
                                                          <s:convertEntity />
                                                     </h:selectManyCheckbox>


                            The first problem the checkboxes are displayted without label and when i clic on the register button i have this error:




                            Exception during request processing:
                            Caused by javax.servlet.ServletException with message: For input string: agent




                            javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
                            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
                            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
                            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                            org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                            org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                            java.lang.Thread.run(Thread.java:662)












                            • 26. Re: how to persist data from selectManyCheckbox
                              lvdberg

                              Hi,


                              try to see the bigger picture.....


                              The userRoles are entities in a Set of the User entity. What you're doing now is creating a check Many list with Strings which you automatically try to convert to an Entity. This won't work.
                              The error states that also:


                              Caused by javax.servlet.ServletException with message: For input string: agent



                              Go back to the basics. You have a User who has 0 or more UserRoles The Query should read the entity (as provided in my example) which must be inserted in the Set.


                              Reread the previous answers and hints and do some rethinking in entities. As mentioned before look into the Rich faces component and you will see an excellent select box component which will do this trich without a problem.


                              Leo.

                              • 27. Re: how to persist data from selectManyCheckbox
                                wadhah

                                Leo
                                I will want to assign roles to a user during registration how should i proceed?

                                • 28. Re: how to persist data from selectManyCheckbox
                                  lvdberg

                                  Hi,


                                  Make a page with inputs for all the normal attributes and a Pick list for the roles. You can take different approaches. First create the user and add the roles later or all at-once
                                  .


                                  Leo

                                  • 29. Re: how to persist data from selectManyCheckbox
                                    wadhah

                                    Leo this is my role entity



                                    package org.domain.seam.entity;
                                    
                                    import java.io.Serializable;
                                    import javax.persistence.Entity;
                                    import javax.persistence.Id;
                                    import javax.persistence.GeneratedValue;
                                    import javax.persistence.Table;
                                    import org.hibernate.validator.Length;
                                    import org.jboss.seam.annotations.Name;
                                    import org.jboss.seam.annotations.security.management.RoleName;
                                    
                                    @Name("role")
                                    @Entity
                                    @Table(name = "Role")
                                    public class Role implements Serializable {
                                         /**
                                          * 
                                          */
                                         private static final long serialVersionUID = 2392158972471437066L;
                                    
                                         private Long id;
                                         private String rolename;
                                    
                                         @Id
                                         @GeneratedValue
                                         public Long getId() {
                                              return id;
                                         }
                                    
                                         public void setId(Long id) {
                                              this.id = id;
                                         }
                                    
                                         @RoleName
                                         @Length(max = 20)
                                         public String getRolename() {
                                              return rolename;
                                         }
                                    
                                         public void setRolename(String rolename) {
                                              this.rolename = rolename;
                                         }
                                    
                                    }


                                    This is my User entity



                                    package org.domain.seam.entity;
                                    
                                    import java.io.Serializable;
                                    import java.util.ArrayList;
                                    import java.util.List;
                                    import javax.persistence.Entity;
                                    import javax.persistence.Id;
                                    import javax.persistence.GeneratedValue;
                                    import javax.persistence.JoinColumn;
                                    import javax.persistence.JoinTable;
                                    import javax.persistence.ManyToMany;
                                    import javax.persistence.Table;
                                    import org.hibernate.validator.Length;
                                    import org.hibernate.validator.NotNull;
                                    import org.jboss.seam.annotations.Name;
                                    import org.jboss.seam.annotations.security.management.UserRoles;
                                    
                                    @Entity
                                    @Name("user")
                                    @Table(name = "User")
                                    public class User implements Serializable {
                                    
                                         /**
                                          * 
                                          */
                                         private static final long serialVersionUID = -2133760147013842042L;
                                         private Long id;
                                         private String name;
                                         private String password;
                                         private String username;
                                         private List<Role> roles = new ArrayList<Role>();
                                    
                                         @Id
                                         @GeneratedValue
                                         public Long getId() {
                                              return id;
                                         }
                                    
                                         public void setId(Long id) {
                                              this.id = id;
                                         }
                                    
                                         @Length(max = 20)
                                         @NotNull
                                         public String getName() {
                                              return name;
                                         }
                                    
                                         public void setName(String name) {
                                              this.name = name;
                                         }
                                    
                                         @Length(max = 20)
                                         @NotNull
                                         public String getPassword() {
                                              return password;
                                         }
                                    
                                         public void setPassword(String password) {
                                              this.password = password;
                                         }
                                    
                                         @Length(max = 20)
                                         @NotNull
                                         public String getUsername() {
                                              return username;
                                         }
                                    
                                         public void setUsername(String username) {
                                              this.username = username;
                                         }
                                    
                                         @ManyToMany(targetEntity = Role.class)
                                         @UserRoles
                                         @JoinTable(name = "UsersRoles", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
                                         public List<Role> getRoles() {
                                              return roles;
                                         }
                                    
                                         public void setRoles(List<Role> roles) {
                                              this.roles = roles;
                                         }
                                    }



                                    This is my RegisterBean



                                    package org.domain.seam.session;
                                    
                                    
                                    import javax.ejb.Stateless;
                                    import javax.persistence.EntityManager;
                                    import javax.persistence.PersistenceContext;
                                    import org.domain.seam.entity.User;
                                    import org.jboss.seam.annotations.Name;
                                    import org.jboss.seam.annotations.In;
                                    import org.jboss.seam.annotations.Logger;
                                    import org.jboss.seam.log.Log;
                                    import org.jboss.seam.international.StatusMessages;
                                    
                                    @Stateless
                                    @Name("Register")
                                    public class RegisterBean implements Register {
                                         @Logger
                                         private Log log;
                                    
                                         @In
                                         StatusMessages statusMessages;
                                         @In
                                         private User user;
                                         @PersistenceContext
                                         private EntityManager em;
                                    
                                         public User getUser() {
                                              return user;
                                         }
                                    
                                         public void setUser(User user) {
                                              this.user = user;
                                         }
                                    
                                         public String register() {
                                              // implement your business logic here
                                              // log.info("Register.register() action called");
                                              // statusMessages.add("register");
                                              em.persist(user);
                                              return "/registered.xhtml";
                                         }
                                    
                                    }
                                    



                                    This is my RoleListingBean






                                    package org.domain.seam.session;
                                    
                                    import java.util.ArrayList;
                                    import java.util.List;
                                    
                                    import javax.ejb.Stateless;
                                    import javax.persistence.EntityManager;
                                    import javax.persistence.PersistenceContext;
                                    
                                    import org.domain.seam.entity.Role;
                                    import org.domain.seam.entity.User;
                                    import org.jboss.seam.ScopeType;
                                    import org.jboss.seam.annotations.Factory;
                                    import org.jboss.seam.annotations.Name;
                                    import org.jboss.seam.annotations.In;
                                    import org.jboss.seam.annotations.Logger;
                                    import org.jboss.seam.annotations.Out;
                                    import org.jboss.seam.annotations.Scope;
                                    import org.jboss.seam.log.Log;
                                    import org.jboss.seam.international.StatusMessages;
                                    
                                    @Stateless
                                    @Name("RoleListing")
                                    @Scope(ScopeType.APPLICATION)
                                    public class RoleListingBean implements RoleListing {
                                         @Logger
                                         private Log log;
                                    
                                         @In
                                         StatusMessages statusMessages;
                                    
                                         @PersistenceContext
                                         private EntityManager em;
                                         @In
                                         private User user;
                                         @Out
                                         private List<Role> roles = new ArrayList<Role>(user.getRoles());
                                    
                                         @Factory("roles")
                                         public List<Role> getRoles() {
                                              roles = em.createQuery("select id,rolename from Role").getResultList();
                                              return roles;
                                         }
                                    
                                         public void setRoles(List<Role> roles) {
                                              this.roles = roles;
                                         }
                                    
                                         public void roleListing() {
                                              // implement your business logic here
                                              log.info("RoleListing.roleListing() action called");
                                              statusMessages.add("roleListing");
                                         }
                                    
                                         // add additional action methods
                                    
                                    }
                                    


                                    This is my register.xhtml



                                    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                                        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                                    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                                         xmlns:s="http://jboss.com/products/seam/taglib"
                                         xmlns:ui="http://java.sun.com/jsf/facelets"
                                         xmlns:f="http://java.sun.com/jsf/core"
                                         xmlns:h="http://java.sun.com/jsf/html"
                                         xmlns:rich="http://richfaces.org/rich"
                                         xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
                                    
                                         <ui:define name="body">
                                    
                                              <rich:panel>
                                    
                                                   <f:facet name="header">register</f:facet>
                                    
                                                   <h:form id="RegisterForm">
                                                        <h:panelGrid columns="2">
                                                          Username: <h:inputText value="#{user.username}" required="true" />
                                    
                                                      Real Name: <h:inputText value="#{user.name}"
                                                                  required="true" />
                                                      Password: <h:inputSecret value="#{user.password}"
                                                                  required="true" />
                                                        Role: <rich:pickList value="#{user.roles}">
                                                                  <s:selectItems var="_role" value="#{RoleListing.roles}" />
                                                             </rich:pickList>
                                                        </h:panelGrid>
                                    
                                                        <h:commandButton id="register" value="register!"
                                                             action="#{Register.register}" />
                                    
                                                   </h:form>
                                    
                                              </rich:panel>
                                    
                                         </ui:define>
                                    
                                    </ui:composition>


                                    Finally this is the error :



                                    Error reading 'roles' on type org.javassist.tmp.java.lang.Object_$$_javassist_seam_2



                                    PS : I am really sorry LEO