0 Replies Latest reply on Sep 5, 2007 11:42 AM by Marco Brandizi

    Examples about Application Framework (Chapter 11)

    Marco Brandizi Newbie

      Hi all,

      I cannot make the examples in chapter 11 working:

      I've started with Person and PersonHome, with the creation button only. And worked up to that point.

      Then I've added update and delete, and I've added a query object, so that I can have an access point to the edit page.

      What I get is: 1) Creation still works 2) when I select some item to be updated and I submit the edit form anything is updated. If I click on delete, anything is deleted either 3) After having clicked on update or delete, I am bring back to the creation page (with Create button only)

      I've tried to extend update() in PersonHome, to add a logging message, and I may see the method is not called at all, same for delete. I also have tried to add a foo() action to the home, and this isn't called either.

      Please find the code below. I am afraid I am missing something important.

      Thanks in advance for any help.




      import java.io.Serializable;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.ScopeType;
      public class Person implements Serializable {
       @Id @GeneratedValue private Long id;
       private String name;
       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; }

      import javax.ejb.Stateful;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.*;
      import uk.ac.ebi.microarray.model.Person;
      import org.jboss.seam.framework.EntityHome;
      import org.jboss.seam.annotations.web.RequestParameter;
      import org.jboss.seam.log.Log;
      public class PersonHome extends EntityHome<Person>
       @RequestParameter Long personId;
       @Logger private Log log;
       public Long getId () {
       return personId;
       public void setId ( Long id ) {
       personId = id;
       @Factory( "person" )
       public Person initPerson () { return getInstance (); }
       public String update ( )
       log.info ( ">>> Calling PersonHome.update()" );
       return super.update ();
       public String persist ( )
       log.info ( ">>> Calling PersonHome.persist()" );
       return super.persist ();
       public String foo ( )
       log.info ( ">>> Calling PersonHome.foo()" );
       return super.update ();

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       <ui:define name="body">
       <h:outputText rendered = "#{!personHome.managed}" value = "New Person" />
       <h:outputText rendered = "#{personHome.managed}" value = "Edit Person" />
       Name: <h:inputText value="#{person.name}"/><br/><br/>
       <h:commandButton value="Create Contact" action="#{personHome.persist}" rendered="#{!personHome.managed}"/>
       <h:commandButton value="Update Contact" action="#{personHome.update}" rendered="#{personHome.managed}"/>
       <h:commandButton value="Delete Contact" action="#{personHome.remove}" rendered="#{personHome.managed}"/>
       <h:commandButton value="Foo" action="#{personHome.foo}" rendered="#{personHome.managed}"/>
       <h:messages styleClass="message"/>

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       <ui:define name="body">
       <h1>List of people</h1>
       <h:dataTable value="#{people.resultList}" var="person">
       <s:link view="/person.seam" value="#{person.name}">
       <f:param name="personId" value="#{person.id}"/>

      Also I have the parameter specification in pages.xml:
       <page view-id="/person.xhtml">
       <param name="personId" value="#{person.id}"/>

      And the query spec in components.xml:
      <framework:entity-query name="people" ejbql="select p from Person p"/>