Showing posts with label JBoss Seam. Show all posts
Showing posts with label JBoss Seam. Show all posts

Monday, November 24, 2014

Seam’s Integration with the MVC

Most frameworks integrate directly by having you call their framework-specific servlets to
integrate with the architecture. Seam is different; it controls items by adding listeners and
life cycles into the request. This allows us to maintain the normal life cycle of a JSF
request. You saw this already earlier in the chapter when I presented Seam’s basic configuration.
Here I will explain it in a bit more detail.
Before I start explaining how Seam integrates with the various areas, you need to be
aware of a central class: org.jboss.seam.context.Lifecyle. This is the class that will keep
our contexts straight. Contexts will handle state in the web tier in a more advanced way
than a standard request and session object.
As you may recall, in the web.xml a listener (org.jboss.seam.servlet.SeamListener) was
added. You also see this listener being the first thing called in our sequence diagram. This
listener is called only at the start of a new session. This will set ServletContext and Session
to the Lifecycle object for manipulation later.
Now you see the next object called is SeamPhaseListener. The SeamPhaseListener object
is called in connection with FacesServlet. As you saw in faces-config.xml earlier, the
SeamPhaseListener is part of the life cycle for FacesServlet. This again is used to control
much of the context and to store the request state. This listener is needed to help move
the data from the presentation to the business logic tier. In a typical JSF life cycle, you
would use backing beans. Now instead of having to worry about your backing beans
needing to translate the data and call EJBs, Seam will handle this directly for us.


Copied from: Beginnign JBoss Seam by Joseph Faisal Nusairat

Inversion of Control in Seam

Inversion of control, also known by many as dependency injection, takes the need to
instantiate objects away from the normal user calls. Instead, you allow the container to
handle the creation of the component and its subcomponents. Seam is no different in
using dependency injection to inject objects. However, Seam takes it to the next step by
allowing the injection to go both ways.

IoC is needed because of the nature of Seam. Because we don’t use any JSF action
classes to translate our presentation tier requests into objects and then set them on the
EJB and call the EJB, we have to use IoC to make up for it. This helps us save time and
space by letting the container manage the objects.

The usage of IoC in Seam is often referred to as bijection, because the injection is
two-way (injection and “outjection”). You can specify the direction of the components.
However, bijection is so much more in Seam than it is in most typical IoC patterns. Seam
takes IoC and expands it by making it dynamic, contextual, and bidirectional, and allowing
assembly by the container.

So where can you use bijection? Bijection can be used on any object that is a Seam
object. Remember, a Seam object is any object that you have defined with an @Name annotation
on the class. You can then biject your Seam objects into any SB or JavaBean.
However, you cannot biject objects into your EB. This is because the domain model
should be independent of business logic and because EBs are instantiated at the application
level and Seam could not intercept them anyway.

Seam performs bijection by dividing it into two areas: one going into the system and
one going out. As I have said, these are more commonly defined as injection and outjection,
and we use @In and @Out for these, respectively.