1.2.2. How it works
When the form is submitted, JSF asks Seam to resolve the variable named
user
. Since no value is yet bound to that name (in any Seam context), Seam instantiates the user
component, and returns the resulting User
entity bean instance to JSF after storing it in the Seam session context.
The form input values are now validated against the Hibernate Validator constraints specified on the
User
entity. If the constraints are violated, JSF redisplays the page. Otherwise, JSF binds the form input values to properties of the User
entity bean.
Next, JSF asks Seam to resolve the variable named
register
. Seam uses the JNDI pattern mentioned earlier to locate the stateless session bean, wraps it as a Seam component, and returns it. Seam then presents this component to JSF and JSF invokes the register()
action listener method.
Seam then intercepts the method call and injects the
User
entity from the Seam session context, before allowing the invocation to continue.
The
register()
method checks if a user with the entered username already exists. If so, an error message is queued with the FacesMessages
component, and a null outcome is returned, causing a page redisplay. The FacesMessages
component interpolates the JSF expression embedded in the message string and adds a JSF FacesMessage
to the view.
If no user with that username exists, the
"/registered.xhtml"
outcome triggers a browser redirect to the registered.xhtml
page. When JSF comes to render the page, it asks Seam to resolve the variable named user
and uses property values of the returned User
entity from Seam's session scope.