Hi guys,

Here's a little design suggestion. I don't know if you have already
discussed this.

As we all know Action and ActionForm makes use of parts of the Servlet API
(HttpRequest).
This ties the execution of Action and ActionForm to a servlet enviroment.
This is not bad, but (imho) it isn't good either...

* We are not able to test our Actions in other enviroments (JUNIT for
instance)
* It's not possible to port our Action and ActionForm implementations to
other types of applications (applet,    console)

A couple of month ago I implemented my own Model2 framework that worked with
a socalled RequestContext.
The RequestContext contained three HashSet's, representing request-, session
and applicationattributes
In the Servlet's service (post/get) method we would populate the
RequestContext with all request, session and applications attributes and
pass it along the our viewvalidator (in this case an ActionForm object),
that would extract the needed parameters and react to them (this could still
be done with reflection as in struts).
Any output from the validation would then be placed in the RequestContext's
Collection (as a proxy to the *real* HttpRequest, HttpSession, etc,
objects).
If the validation was succesful the Servlet would then pass the
RequestContext to a Command (or Action). The command would then extract it
needed parameters and work on them.
Once again, output would be place in the RequestContext's representation of
Request, Session and Application.
When the Command (or Action) was completed, the Servlet would iterate
through the RequestContext and place all the attributes into their
respective scope.

The important point here is that the RequestContext wasn't tied to the
Servlet API, although it could be initialized with HTTPRequest as parameter.

By doing the above we were able to create validations and actions that we
could easily test and reuse.
What we usually did was that we created JUNIT testcases where we created
instances of RequestContext and passed it to our Actions and eveluated the
return values...These JUNIT cases could then be run from anywhere.
We actually had our deployment done by Ant, and our deployment scripts would
run all our testcases before deploying...
We could actually test "all" of our application from the commandline...

Just my two cents...

Mikkel Bruun

Reply via email to