1 Reply Latest reply on May 7, 2008 12:07 PM by jpviragine.jpviragine.gmail.com

    Seam problem with SelectOneMenu

    lbertrand

      Hi,
      I think I've a big problem with understanding Seam.
      I'm trying to make a simple new user form, but I'm on the wrong way I think, because it doesn't work :


      I've a User entity class :


      @Entity
      @Name("user")
      @Table(name = "user", catalog = "mydb")
      public class User implements java.io.Serializable {
       
           private int uCode;
           private UserType userType;
           private String uFirstname;
           private String uLastname;
           private String uPhone;
           private String uEmail;
      
      then getters and setters...



      I've a UserType entity class :



      @Entity
      @Name("userType")
      @Table(name = "usertype", catalog = "mydb")
      public class UserType implements java.io.Serializable {
       
           private int utCode;
           private String utName;
      then getters and setters...



      I have also a Session bean which manages my page :



      @Stateful
      @Name("userBean")
      @Scope(ScopeType.SESSION)
      public class UserBean implements IUser {
       
           @In(required=false)
           @Out(required=false) 
           User user;
           
           @DataModel
           private List<User> users;
           
           @PersistenceContext
           EntityManager entityManager;
           
           public String add()
           {
                  em.persist(user);
              }
      }



      and finally, here is my view :



      <!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"
                      template="layout/template.xhtml"
                      xmlns:a4j="http://richfaces.org/a4j">
       
      <ui:define name="body">
       
          <h:messages globalOnly="true" styleClass="message"/>
          
          <rich:panel>
          <f:facet name="header">#{messages.newcustomer}</f:facet>
          <p>#{messages.completethisform} :</p>
          <h:form>
               <table border="0" width="600px">
               <tr>
                    <td>#{messages.lastname} :</td>
                    <td><h:inputText value="#{user.uLastname}" /></td>
               </tr>
               <tr>
                    <td>#{messages.firstname} :</td>
                    <td><h:inputText value="#{user.uFirstname}" /></td>
               </tr>
               <tr>
                    <td>#{messages.usertype} :</td>
                    <td>
                         <h:selectOneMenu value="#{user.userType}" >
                              <s:selectItems value="#{allusertypes}" var="type" label="#{type.utname}"  />
                              <s:convertEntity  />
                         </h:selectOneMenu>
                         
                    </td>
               </tr>
               <tr>
                    <td>#{messages.email} :</td>
                    <td><h:inputText value="#{utilisateur.utemail}" /></td>
               </tr>
               <tr>
                    <td>#{messages.phone} :</td>
                    <td><h:inputText value="#{user.uPhone}" /></td>
               </tr>
               </table>
               <h:commandButton action="#{userBean.add}" value="Ok" type="submit"  ></h:commandButton>
          </h:form>
          </rich:panel>
      </ui:define> 
      </ui:composition>



      The main problem concerns the selectOneMenu, because I can't get the UserType value in my User Entity, and I have
      this kind of error in my Eclipse Console :


      INFO  [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
      sourceId=j_id49:j_id57[severity=(ERROR 2), summary=(j_id49:j_id57: Erreur de validation: Valeur not valid.), detail=(j_id49:j_id57: Erreur de validation: Valeur not valid.)]
      



      Could someone help me please ?