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

    Simple HelloWorld not running

    Alex Kavo Novice

      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.