Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

To keep signatures brief, and methods useful, SAF2 uses two techniques: Dependency Injection and Thread Local, both of which, in turn, rely on the ActionContext.

Dependency Injection

Many Interceptors are used to populate propertes on an Action. For example, the Servlet Config Interceptor can set Map properties representing the HTTP Request, Session, and Appplication objects.

...

So how does an Interceptor obtain the HTTP contexts to inject?

ThreadLocal

The ThreadLocal class is not a new kid on the block. It's been available to developers since Java 1.2. In effect, each thread has its own copy of the variables on a ThreadLocal class.

SAF2 uses ThreadLocal in connection with the ActionContext class to make servlet configuration and other runtime details available.

ActionContext

From anywhere within an SAF2 application, you can obtain a reference to the ActionContext by calling

...

The darker side is that classes that depend heavily on ThreadLocal can be diffcult to unit test. A cleaner design centralizes access to ThreadLocal variables, so that other classes are easier to test.

Back to Migration Guide

...

This material originally adopted from http://wiki.apache.org/struts/ActionContext?action=edit.