Please post comments or corrections to the Author online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=351
The tricky, and powerful, thing about the ValueStack and OGNL is that they don't belong
to any of the individual framework components. In Figure 1.4, note than both interceptors and
results can use OGNL to target values on the ValueStack. The data in the ValueStack follows the
request processing through all phases; it slices through the whole length of the framework. It can
do this because it is stored in a ThreadLocal context called the ActionContext.
Definition: OGNL is a powerful expression language, and more, that is used to reference
and manipulate properties on the ValueStack.
The ActionContext contains all of the data that makes up the context in which an action
occurs. This includes the ValueStack obviously, but it also includes stuff the framework itself
will use internally, like the request, session, and application maps from the Servlet API. You can
definitely access these objects yourself if you like, and we'll see how later in the book. For now,
we just want to focus on the ActionContext as the ThreadLocal home of the ValueStack. The use
of ThreadLocal makes the ActionContext, and thus the ValueStack, accessible from anywhere in
the same thread of execution. Since Struts 2's processing of each request occurs in a single
thread, the ValueStack is available from any point in the framework's handling of a request.
Typically, its considered bad form to obtain the contents of the ActionContext yourself.
The framework provides many elegant ways to interact with that data with out actually touching
the ActionContext, or the ValueStack, yourself. Primarily, you will use OGNL to do this. OGNL
is used in many places in the framework to reference and manipulate data in the ValueStack. For
instance, you will use OGNL to bind HTML form fields to data objects on the ValueStack for
data transfer, and you will use OGNL to pull data into the rendering of your JSP's and other result
types. At this point, you just need to understand that the ValueStack is where your data is stored
while you work with it, and that OGNL is the expression language that you, and the framework,
use to target this data from various parts of the request processing cycle.
Now you've seen how Struts 2 implements MVC, and you've got a brief introduction to
all the other important players in the processing of actual requests. The next thing we need to do,
before getting down to the nuts and bolts of the framework’s core components, is to make all of
this concrete with a the simple HelloWorld application of Chapter Two. But first, a quick
summary.
1.4 Summary
We started with a lot of abstract stuff about frameworks and design patterns, but you
should now have a fairly good high level understanding of the Struts 2 architecture. If abstraction
is not to your taste, you'll be happy to know that we've officially completed the theoretical portion
of the book. Starting immediately with Chapter Two's HelloWorld application, the rest of the
book will deal with only the concrete, practical matters of building web applications. But before
we move on, let's take a moment to review the things we've learned.
We should probably spend a moment or two to evaluate Struts 2 as a framework. Based
upon our understanding of the technological context and the common domain tasks, we laid out
two responsibilities for a web application framework at the outset of this chapter. First, we said
that a framework should provide an architectural foundation for web applications. We've seen
that Struts 2 certainly does this, and we discussed the design pattern roots that inform the Struts 2
architectural decisions. In particular, we have seen that Struts 2 takes the lessons learned from
first generation web application frameworks to implement a brand new, cleaner MVC based
Licensed to Lisa Williams <anhmytl@oatoz.net>