aspose file tools*
The moose likes Other Application Frameworks and the fly likes Seam Book (Yuan & Heute) Hello World Example Annotation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Seam Book (Yuan & Heute) Hello World Example Annotation" Watch "Seam Book (Yuan & Heute) Hello World Example Annotation" New topic
Author

Seam Book (Yuan & Heute) Hello World Example Annotation

John Peters
Greenhorn

Joined: May 25, 2007
Posts: 18
In Michael & Thomas' Seam book, in the chapter 2 Hello World example, why is the "person" variable outjected? Doesn't the "@Name" annotation on the Person entity already make the "person" available to Seam?
Thanks!

SLSB:


Entity:


XHTML:

[ February 11, 2008: Message edited by: John Peters ]
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

You use @Name to tell Seam that this is a Seam component and the component will be bijected under this name (you can override it however).
To actually outject a component you need to use @Out.
HTH.
John Peters
Greenhorn

Joined: May 25, 2007
Posts: 18
Hey John, thanks for the reply. I think I'm following you, but I'd like some clarification, please:

I was playing around with the SLSB and removed the "@Out" annotation on the "person" variable, so the SLSB looks like this:

Afer redeploying the EAR, everything still worked without any problems. My confusion is why did the authors annotate the "person" class (that is injected in the SLSB) with "@Out" to begin with? It appears Seam was able to create an entity bean just by using the "@Name" annotation on the entity bean itself, and the "@Out" annotation on the SLSB for the "person" class was redundant. Is this correct or am I missing something?

Thanks again, for your help. I've been reading everything I can on bijection and still haven't had the epiphany I need.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Think of it in this way:
When you annotate a Seam component with @Out, you are telling Seam that you want to store this component under some scope.
Remember those lines:
PurchaseOrder po = new PurchaseOrder();
session.setAttribute("purchaseOrder", po);
When you are using @Out, you are doing the same thing.
Alternativley, when you are using @In, you are telling Seam you want to get the object from a desired scope (context in Seam parlance)
Remember this line:
session.getAttribute("purchaseOrder");
?
In your case, yes sure, you can remove @Out from person declaration but you can't write this in your view page:
<h utputText value="#{person.age}" />
Because it is not stored under a scope, you have to write:
<h utputText value="#{helloAction.person.age}" />
Actually, you have to avoid the excessive use bijection as it could harm the performance.
John Peters
Greenhorn

Joined: May 25, 2007
Posts: 18
Sorry for the late reply.
I think I'm getting it now, thanks to your help.

One thing I noticed that I think helped me finally get it was that when the @Out annotation was removed from:

the text box no longer was blank after a submit. I figured out that it wasn't blank because after the "person" variable was set to a new blank person, (person = new Person() )it wasn't "pushed" back out to Seam to pick up.

Let me restate it so I make sure I get it:
You're using the @In and @Out to inject and outject items from the Seam contexts which are held in different scopes (session,conversation,page,etc) under names defined by the @Name annotation.

When the xhtml form is submitted, it creates an entity bean (in this case, a Person)based off of how the "value" tags are set up on the "inputText". The @In annotation allows the SLSB to bring in that entity bean from the Seam context into the variable named "person" and persist it. After the entity is persisted, the "person" variable is set to a new, empty person, outjected back into the Seam context where it is rerendered on the xhtml page as a blank Person entity.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Seam Book (Yuan & Heute) Hello World Example Annotation