14 Replies Latest reply on Jun 19, 2008 11:42 AM by coolex

    Simple HelloWorld not running

    coolex

      Hello!


      I'm trying to start working with SEAM.
      I wrote this simple person class


      package com.test;
      
      import java.io.Serializable;
      
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      
      import org.hibernate.annotations.Entity;
      import org.jboss.seam.annotations.Name;
      
      @Entity
      @Name("person")
      public class Person implements Serializable {
              
              /**
               * 
               */
              private static final long serialVersionUID = 1L;
              
              private long id;
              private String name;
      
              @Id
              @GeneratedValue
              public long getId() {
                      return id;
              }
      
              public void setId(long id) {
                      this.id = id;
              }
      
              public String getName() {
                      return name;
              }
      
              public void setName(String name) {
                      this.name = name;
              }
      }


      This java file I simply created in the src/model directory.


      Then I created this file (ManagerAction.java):


      package com.test;
      
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      
      import com.test.Person;
      
      @Stateless
      @Name("manager")
      public class ManagerAction implements Manager {
              @In
              @Out
              private Person person;
      
              @Out
              private List<Person> fans;
      
              @PersistenceContext
              private EntityManager em;
      
              public String sayHello() {
                      em.persist(person);
                      person = new Person();
                      fans = em.createQuery("select p from Person p").getResultList();
                      return null;
              }
      }



      And this Interface (Manager.java):


      package com.test;
      
      import javax.ejb.Local;
      
      @Local
      public interface Manager {
              public String sayHello ();
      }
      


      At least I created this xhtml file:


      <!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:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets">
      <head>
                <link href="stylesheet/theme.css" rel="stylesheet" type="text/css" />
            <title>Register New User</title>
      </head>
      <h:form>
              Please enter your name:<br/>
              <h:inputText value="#{person.name}" size="15"/><br/>
              <h:commandButton type="submit" value="Say Hello"
              action="#{manager.sayHello}"/>
      </h:form>
      
      <h:dataTable value="#{fans}" var="fan">
              <h:column>
                      <h:outputText value="#{fan.name}"/>
              </h:column>
      </h:dataTable>
      
      </html>


      Ok, I deployed it and can enter the screen and see the form but after submitting I get the debug page with this error:



      Caused by javax.servlet.ServletException with message: "/helloworld.xhtml @12,49 value="#{person.name}": Target Unreachable, identifier 'person' resolved to null"



      Why it cannot resolve person? It is there!
      Hope you can help me.


      Thanks.

        • 1. Re: Simple HelloWorld not running
          coolex

          Please, give me a hint!

          • 2. Re: Simple HelloWorld not running
            endyamon

            Try this...


            @In(create=true)
            @Out
            private Person person;
            

            • 3. Re: Simple HelloWorld not running
              coolex

              Thanks for answer. Unfortunately it does not solve the problem.
              I got the hello world example from a book.


              Maybe the problem is how I create the java files in Eclipse? Because after creating them SEAM must create some configurations in XML files, like components.xml, faces-config.xml or pages.xml.
              I think that does not happen. But I don't know any other way how to create the beans in Eclipse to make them available for SEAM.


              Hope you know it.

              • 4. Re: Simple HelloWorld not running
                charliepower76

                You should really install the JBoss Tools plug in for Eclipse. Creating Seam projects (and components) is very easy with this. It works out of the box.


                Just create a new Seam Project with the wizard, and then right-click on your project to create entities, actions, etc.

                • 5. Re: Simple HelloWorld not running
                  coolex

                  OK, before I created a project vie the windows console and the command SEAM setup, SEAM new-project, then I created the java files. Is this not the right way?

                  • 6. Re: Simple HelloWorld not running
                    endyamon

                    yeah! it seems to be something in components.xml but you could try this. I guess


                    <h:inputText value="#{manager.person.name}" size="15"/><br/>
                    


                    • 7. Re: Simple HelloWorld not running
                      coolex

                      The problem with creating the project with the plugin was that the wizard says (the screen where I have to specify my SEAM location) wrong version but I have the latest and don't want to change my SEAM to an old version. so maybe I can create the java files via the console?

                      • 8. Re: Simple HelloWorld not running
                        charliepower76

                        Both ways are good (usually), but i think it's better for you to have to Seam plug in for Eclipse (part of the JBoss Tools project), becauses it really eases the development process. Read chapter 3 of the Seam reference guide for more info.

                        • 9. Re: Simple HelloWorld not running
                          charliepower76

                          I think I know why... at the first screen of the wizard, in the configurations section, did you choose Dynamic Web project with Seam 2.0 (technology preview) ? If not, you won't have the option to choose the Seam 2.0 Runtime in the upcoming screens

                          • 10. Re: Simple HelloWorld not running

                            You should post the structure of the archives being created by your build.  Do you have a seam.properties file in the jar containing Person?  The Person component will not be registered without this marker file.


                            Hope it helps.

                            • 11. Re: Simple HelloWorld not running
                              coolex

                              Now I'm using the JBoss Tools Plugin for Eclipse.
                              With Plugin I created all files above.
                              Again I get this error:


                              "/persons.xhtml @9,50 value="#{person.name}": Target Unreachable, identifier 'person' resolved to null"



                              I guess it has something to do with my database but I don't know what exactly. I have a connection. Do I have to create the columns myself? The tables?

                              • 12. Re: Simple HelloWorld not running
                                coolex

                                Is it necessary to have data in the database?

                                • 13. Re: Simple HelloWorld not running
                                  btonez

                                  Add an annotation so your Person class looks like this:


                                  @Entity
                                  @Name("person")
                                  @Scope(ScopeType.SESSION)
                                  public class Person implements Serializable {



                                  If I'm correct, Person was being outjected to the EVENT scope, which is default for a @Stateless manager bean.  So when your form was submitted and, returning null, the page was refreshed, the EVENT scope finished and the Person had disappeared.  Either CONVERSATION or SESSION scope would work.


                                  Hope this helps!

                                  • 14. Re: Simple HelloWorld not running
                                    coolex

                                    Unfortunately it does not solve the problem.
                                    Do I have first to create the tables in the database?
                                    Does SEAM creates the tables from the entity class?
                                    I'm a little bit confused about this database thing.