Quoting Jeff Caddel <[EMAIL PROTECTED]>:

> 
> >If your application uses WebContext (or one of it's subclasses) as the
> Context
> >object being passed down the chain, you already have access to the request
> >attributes via the getRequestScope() method.  There's also other
> Map-returning
> >methods on WebContext for lots of other useful stuff (headers, cookies,
> session
> >attributes, context attributes, context init parameters, ...).
> >
> Ahhhh.  Brain cells starting to click now.  One huge benefit of exposing 
> them as map's being that you can make use of generic bean manipulating 
> code to mess with them, right?  Instead of making API specific calls 
> like getAttribute/setAttribute.
> 

That is certainly one benefit.  A second benefit is the concept of "request
attributes" works across both servlet and portlet environments, without tying
your application code to one or the other underying API for accessing the
request object (and the same principle applies on session and application
scope).

> >
> >On the attribute collections in particular, the Map implementation is
> two-way
> >... for example, usage like this:
> >
> >  public boolean execute(Context context) throws Exception {
> >    ...
> >    WebContext wcontext = (WebContext) context;
> >    // Following is equivalent to request.getAttribute("foo")
> >    String fooValue = wcontext.getRequestScope().get("foo");
> >    // Following is equivalent to request.setAttribute("foo", "bar")
> >    wcontext.getRequestScope().put("foo", "bar");
> >    ...
> >  }
> >
> Which is better since nothing in this implementation makes a servlet 
> specific API call.  If I needed the value "bar" to be present under the 
> attribute "foo" in a portlet environment (for example), this command 
> could be re-used.
> 

Yep.

I should have noted that you can also leverage the attribute-property
transparency built in to the base Context implementation, and say:

  Map requestScope = (Map) context.get("requestScope");

without needing the explicit cast to WebContext.

> >
> >makes a request attribute named "foo" with value "bar" visible to a JSP page
> (or
> >whatever) that will ultimately create the response.
> >
> If I'm getting this right, I could also place "bar" into the request 
> under the attribute "foo" (in an API independent manner, nonetheless) by 
> simply configuring a CopyCommand:
> 
> <command className="org.apache.commons.chain.generic.CopyCommand" 
> toKey="requestScope.foo" from="foo"/>
> 

Right now this wouldn't work -- it would put the object into the Context itself
under key "requestScope.foo" -- but one could certainly create a Copy command
that interpreted the keys as expressions.

> (Assuming that some other previous bit of logic had placed "bar" into 
> the context under the key "foo".)
> 
> Holy smokes...how easy is that!!
> 

:-)

> >
> >Does this satisfy the sorts of requirements you were after?
> >
> Fit's the bill quite nicely, Craig.  Thanks.
> 

Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to