[jboss-user] [JBoss Seam] - Re: Calling a Method on a Home Object

christian_zeidler do-not-reply at jboss.com
Fri Oct 12 11:20:01 EDT 2007


Here comes some code... I hope somebody can give me a hint

Here is the entity:
@Entity
  | public class Foo implements Serializable {
  | 	
  | 	//seam-gen attributes (you should probably edit these)
  | 	private Long id;
  | 	private Integer version;
  | 	private String name;
  | 	
  |     //add additional entity attributes
  | 	
  | 	//seam-gen attribute getters/setters with annotations (you probably should edit)
  | 		
  | 	@Id @GeneratedValue
  | 	public Long getId() {
  | 	     return id;
  | 	}
  | 
  | 	public void setId(Long id) {
  | 	     this.id = id;
  | 	}
  | 	
  | 	@Version
  | 	public Integer getVersion() {
  | 	     return version;
  | 	}
  | 
  | 	private void setVersion(Integer version) {
  | 	     this.version = version;
  | 	}   	
  | 	
  | 	@Length(max=20)
  | 	public String getName() {
  | 	     return name;
  | 	}
  | 
  | 	public void setName(String name) {
  | 	     this.name = name;
  | 	}   	
  | }

Here is the Home object with the printFoo() method I'd like to call when loading the view:
 @Name("fooHome")
  | public class FooHome extends EntityHome<Foo>
  | {
  | 
  |     @RequestParameter 
  |     Long fooId;
  |     
  |     public void printFoo(){
  |     	if(this.instance != null){
  |     		System.out.println(this.instance.getName());
  |     	} else{
  |     		System.out.println("no instance");
  |     	}
  |     }
  |     
  |     @Override
  |     public Object getId() 
  |     { 
  |         if (fooId==null)
  |         {
  |             return super.getId();
  |         }
  |         else
  |         {
  |             return fooId;
  |         }
  |     }
  |     
  |     @Override @Begin
  |     public void create() {
  |         super.create();
  |     }
  | }

I've got this in pages.xml:
    <page view-id="/foo.xhtml" action="#{fooHome.printFoo}"> 
  |         <param name="fooId" value="#{fooHome.id}" />
  |     </page>

Now when I call the page I get following logging output:
17:10:27,848 INFO  [STDOUT] no instance
  | 17:10:27,919 INFO  [STDOUT] Hibernate: select foo0_.id as id25_0_, foo0_.name as name25_0_, foo0_.version as version25_0_ from Foo foo0_ where foo0_.id=?

It tells me that the printFood method is executed before the entity is fetched and therfore the instance is still null. Any idea on how to achieve an other order of execution?

Thank you,
Christian

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4094651#4094651

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4094651



More information about the jboss-user mailing list