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

    Examples about Application Framework (Chapter 11)

      Hi all,

      I cannot make the examples in chapter 11 working:
      http://docs.jboss.com/seam/2.0.0.B1/reference/en/html/framework.html

      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.

      Cheers.

      Marco.





      Person.java

      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;
      
      @Entity
      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; }
      }
      




      PersonHome.java
      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;
      
      @Name("personHome")
      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 ();
       }
      
      
      }
      




      person.xhtml
      <!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:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       template="layout/template.xhtml">
      
       <ui:define name="body">
      
      
       <h1>
       <h:outputText rendered = "#{!personHome.managed}" value = "New Person" />
       <h:outputText rendered = "#{personHome.managed}" value = "Edit Person" />
       </h1>
      
       <h:form>
       Name: <h:inputText value="#{person.name}"/><br/><br/>
      
       <div>
       <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}"/>
       </div>
      
       </h:form>
      
       <h:messages styleClass="message"/>
      
       </ui:define>
      
      </ui:composition>
      



      people.xhtml
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:s="http://jboss.com/products/seam/taglib"
       template="layout/template.xhtml"
       >
      
       <ui:define name="body">
      
       <h1>List of people</h1>
      
       <h:dataTable value="#{people.resultList}" var="person">
       <h:column>
       <s:link view="/person.seam" value="#{person.name}">
       <f:param name="personId" value="#{person.id}"/>
       </s:link>
       </h:column>
       </h:dataTable>
      
       </ui:define>
      
      </ui:composition>
      
      




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




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