4 Replies Latest reply on Aug 9, 2006 6:03 AM by ypasmk

    Problem with forms

    ypasmk

      I have two entity classes users and names with a onetomany relation...the problem is that when I have this names entity in my form when I hit submit nothing happens. If I have only the users in my form everything goes well. The submit action calls the registerUser.register method...anyone can explain me what am I doing wrong..?There is no error messages in jboss btw..

      my register.xhtml page

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
       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:s="http://jboss.com/products/seam/taglib">
      <body>
      
      
      this text won't be displayed
      
      <ui:composition template="extras/template.xhtml">
      <ui:define name="title">
       Registration Form
      </ui:define>
      
      
      <ui:define name="body">
       <h:form id="testForm">
      
       <table border="0">
       <s:validateAll>
      
      
      
      
       <tr>
       <td>Surname</td>
       <td><h:inputText value="#{names.lastname}" /></td>
       </tr>
       <tr>
       <td>FirstName</td>
       <td><h:inputText value="#{names.firstname}" /></td>
       </tr>
       <tr>
       <td>MiddleName</td>
       <td><h:inputText value="#{names.middlename}" /></td>
       </tr>
      
       <!--
       <tr>
       <td>Gender</td>
       <td><h:inputText value="#{author.gender}" /></td>
       </tr>
       <tr>
       <td>Title</td>
       <td><h:inputText value="#{author.title}" /></td>
       </tr>
       <tr>
       <td>Year Of Birth</td>
       <td><h:inputText value="#{author.yearOfBirth}" /></td>
       </tr>
       <tr>
       <td>url</td>
       <td><h:inputText value="#{author.url}" /></td>
       </tr>
       <tr>
       <td>email</td>
       <td><h:inputText value="#{author.email}" /></td>
       </tr>
       <tr>
       <td>keywords</td>
       <td><h:inputText value="#{author.keywords}" /></td>
       </tr>
       <tr>
       <td>Password</td>
       <td><h:inputText value="#{author.password}" /></td>
       </tr>
       <tr>
       <td>Retype Password</td>
       <td><h:inputText value="#{author.retypePassword}" /></td>
       </tr>
       <tr>
       <td>Secret Question</td>
       <td><h:inputText value="#{author.secretQuestion}" /></td>
       </tr>
       <tr>
       <td>Secret Answer</td>
       <td><h:inputText value="#{author.secretAnswer}" /></td>
       </tr> -->
      
       <tr>
       <td></td>
       <td><h:commandButton type="Submit" value="Submit" action="#{registerAuthor.register}" /></td>
       </tr>
       </s:validateAll>
       </table>
      
       </h:form>
      
      
      
      </ui:define>
      
      </ui:composition>
      
      </body>
      </html>
      



      my ejb class
      package uai.entities;
      
      import java.io.Serializable;
      
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import javax.persistence.JoinColumn;
      import javax.persistence.ManyToOne;
      import javax.persistence.Table;
      
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Scope;
      
      
      @Entity
      @Table(name="names")
      @Scope(ScopeType.CONVERSATION)
      public class AuthorName implements Serializable {
      
       /**
       *
       */
       private static final long serialVersionUID = 7854278207664893998L;
       private String lastname;
       private String firstname;
       private String middlename;
       private Long id;
      
      
       @Id
       @GeneratedValue
       public Long getId() {
       return id;
       }
      
       public void setId(Long id) {
       this.id = id;
       }
      
      
       public String getMiddlename() {
       return middlename;
       }
       public void setMiddlename(String middlename) {
       this.middlename = middlename;
       }
      
       @NotNull
       public String getFirstname() {
       return firstname;
       }
       public void setFirstname(String name) {
       this.firstname = name;
       }
      
       @NotNull
       public String getLastname() {
       return lastname;
       }
       public void setLastname(String surname) {
       this.lastname = surname;
       }
      
      
      
      
      
      
      }
      


      and my registerAuthor class

      package uai.blogic;
      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.interceptor.Interceptors;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Create;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.core.FacesMessages;
      import org.jboss.seam.ejb.SeamInterceptor;
      import org.jboss.seam.log.Log;
      
      import uai.entities.AuthorName;
      import uai.entities.testObject;
      import static org.jboss.seam.ScopeType.EVENT;
      
      @Interceptors(SeamInterceptor.class)
      @Stateful
      @Name("registerAuthor")
      public class RegisterAuthor implements Register {
      
       @Logger
       private Log log;
      
      
      
       @In(create=true)
       private transient FacesMessages facesMessages;
      
      
      
       @In @Out
       private AuthorName authorName;
      
       //@In @Out
       //private uai.entities.AuthorUser author;
      
       @PersistenceContext
       private EntityManager em;
      
       public String register() {
      
      
       log.info("hi there");
      
       //log.info("authorname : "+this.author.getEmail());
      
       return "/registered.xhtml";
       }
      
       @Destroy
       @Remove
       public void destroy() {
       //log.info("destroyed (register)");
      
       }
      
      
      
      
      }
      


        • 1. Re: Problem with forms
          pmuir

          When you say 'nothing happens' do you mean that the page reloads but the action method on the backing bean isn't called? If so, then put a h:messages JSF tag on the facelet and see if you have any errors resulting from validation, conversion or model-update.

          I also noticed that you outject the 'names entity' as authorName (from the registerAuthor Seam component) but then refer to it as names on the facelet. Also, at no point do you create a new authorName object to write into.

          • 2. Re: Problem with forms
            ypasmk

            What u mean by saying that at no point I create an authorName to write into? Yes, is like the method is never called when I hit enter. I ll try with the h:messages to see what happens. And thx

            • 3. Re: Problem with forms
              pmuir

              In the code you gave there was neither

              @In(create=true) private AuthorName authorName;


              nor

              ...
              authorName = new AuthorName();
              ...
              


              Do you create a new AuthorName object somewhere else in your code?

              • 4. Re: Problem with forms
                ypasmk

                ok I did the modifications you suggest about the inject name and I put h:messages to my form. No I'm getting for all the fields the Conversion Error. What that means?