You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "David G. Friedman" <hu...@ix.netcom.com> on 2004/10/23 02:23:28 UTC

[Struts-Chain] how to use another chain for preprocessing?

I'm curious about Struts-Chain and have read through the 1.2.4 source on it
plus the 1.3 SVN repository.  I don't see anything suggesting how to make my
action chain itself to another action in the struts-config.xml example.  Nor
do I see anything suggesting how to have an action be processed by a chain
other than the default chain.  Is struts-chain supposed to be as one chain
per web.xml pattern matching?  Are the chains supposed to do that and use a
common struts configuration object? (I.e. Just /do/whatever invokes chain a
but mapping /dothis/whatever3 invokes a different chain?

Thanks for any help.

Regards,
David the Curious (humble@ix.netcom.com)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts-Chain] how to use another chain for preprocessing?

Posted by Bill Keese <bi...@tech.beacon-it.co.jp>.
> To chain actions, you simply return a non-redirect ActionForward which 
> points to a Struts action path.  This is chaining (where a redirect 
> isn't) because it results in the ActionServlet triggering a second 
> "run" through the RequestProcessor's processing flow.

OK, that's what I was thinking, along with using the trick to set the 
arguments on your forwards (see 
http://wiki.apache.org/struts/ForwardingWithDifferentParameter)

>
> This can have some unexpected side effects, which is one reason it's 
> not considered "supported behavior".  Also, as Ted notes on the 
> references Wiki pages, when people chain actions, it is often (though 
> not always) because they haven't got a clean controller architecture.

Fair enough.

> I notice that the email from Craig included in that page is over two 
> years old and heavily references the transition from Struts 1.0 to 
> Struts 1.1; is that still useful this far on?

I don't think so.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts-Chain] how to use another chain for preprocessing?

Posted by Joe Germuska <Jo...@Germuska.com>.
At 4:26 PM +0900 10/25/04, Bill Keese wrote:
>Craig McClanahan wrote:
>
>>* Regarding chaining of actions themselves, if you are using the standard
>>  request processing chain that remains as bad an idea as it has always
>>  been in Struts, and I don't see any reason to make it easier with chaining
>>  than it is today.
>
>Hi Craig.  I was hoping you could explain
>   1) how people typically chain actions in struts
>   2) why it is a bad idea
>
>I have some ideas for answers to both questions but I'd like to hear 
>what you think.

Here's a page in the Wiki about this eternal question:
http://wiki.apache.org/struts/ActionChaining

To chain actions, you simply return a non-redirect ActionForward 
which points to a Struts action path.  This is chaining (where a 
redirect isn't) because it results in the ActionServlet triggering a 
second "run" through the RequestProcessor's processing flow.

This can have some unexpected side effects, which is one reason it's 
not considered "supported behavior".  Also, as Ted notes on the 
references Wiki pages, when people chain actions, it is often (though 
not always) because they haven't got a clean controller architecture.

I notice that the email from Craig included in that page is over two 
years old and heavily references the transition from Struts 1.0 to 
Struts 1.1; is that still useful this far on?

I'm not sure who the "I" is in the lead-in to that page is.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

Re: [Struts-Chain] how to use another chain for preprocessing?

Posted by Bill Keese <bi...@tech.beacon-it.co.jp>.
Craig McClanahan wrote:

>* Regarding chaining of actions themselves, if you are using the standard
>  request processing chain that remains as bad an idea as it has always
>  been in Struts, and I don't see any reason to make it easier with chaining
>  than it is today.  
>

Hi Craig.  I was hoping you could explain
   1) how people typically chain actions in struts
   2) why it is a bad idea

I have some ideas for answers to both questions but I'd like to hear 
what you think.

Thanks,
Bill


>The code that is in the repository now has focused on providing a
>chain implementation that is fundamentally backwards compatible with
>existing Struts 1.1/1.2 functionality.  As such, it emulates the
>current RequestProcessor architecture by passng all requests through a
>single commonly configured pipeline (which can, of course, be
>customized).
>
>Going beyond strict backwards compatibility, there's lots of options:
>
>* A chain can already invoke another chain using the generic LookupCommand
>  capability.  The "other" chain's name can be determined either
>literally (via the
>  "name" property) or indirectly (via the "nameKey" property, naming a context
>  property where some other processing logic has stored the name of the chain
>  to be executed).
>
>* Given this, it would be trivial, for example, to create a chain equivalent to
>  the standard DispatchAction, which based the name of the chain to run on some
>  request parameter, or other incomding characteristic on the request.
>  In the "servlet-standard" chain, this technique is used to execute a
>  user-defined preprocess chain if there is one, ignoring it otherwise.
>
>* Alternatively, it would be possible to set things up so that the name of the
>  action implicitly selects a correspondingly named chain (if there is one);
>  defaulting to the standard chain if there is nothing special.  That way you
>  could customize the processing of individual actions without having to
>  affect all of them.
>
>* Regarding chaining of actions themselves, if you are using the standard
>  request processing chain that remains as bad an idea as it has always
>  been in Struts, and I don't see any reason to make it easier with chaining
>  than it is today.  Instead, a different approach is likely to be better -- for
>  example, building a chain that forwards to a view named "foo" could
>  automatically look up a setup chain (specific to that view) and execute
>  it if it's there.  This would likely eliminate many occurrences of the "setup
>  action --> view --> process action" design that you see in lots of
>Struts code.
>
>What a chain does is totally up to who designs the chain.  Once you
>free yourself from a requirement to be backwards compatible (leaving
>the existing servlet-standard chain there for people that *do* want
>that), there's a lot of room to innovate.  So, the answer to nearly
>all of yor questions is "yes, you can do that if you want to."
>
>Craig
>
>
>On Fri, 22 Oct 2004 20:23:28 -0400, David G. Friedman
><hu...@ix.netcom.com> wrote:
>  
>
>>I'm curious about Struts-Chain and have read through the 1.2.4 source on it
>>plus the 1.3 SVN repository.  I don't see anything suggesting how to make my
>>action chain itself to another action in the struts-config.xml example.  Nor
>>do I see anything suggesting how to have an action be processed by a chain
>>other than the default chain.  Is struts-chain supposed to be as one chain
>>per web.xml pattern matching?  Are the chains supposed to do that and use a
>>common struts configuration object? (I.e. Just /do/whatever invokes chain a
>>but mapping /dothis/whatever3 invokes a different chain?
>>
>>Thanks for any help.
>>
>>Regards,
>>David the Curious (humble@ix.netcom.com)
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Struts-Chain] how to use another chain for preprocessing?

Posted by Joe Germuska <Jo...@Germuska.com>.
>After skimming through WebWork2 (dirty word, huh?)

No, actually, I respect the OpenSymphony folks a lot, and I am 
interested in learning everything possible from people who are 
enthusiastic about WebWork.  I am (and the team of developers I 
manage are) too familiar with Struts to make switching wholesale to 
another framework practical (which I don't even know if I'd want to 
do) but why bother, when Struts is open to modifications and 
extensions.

Anyway, I have been looking forward for a while to seeing people 
start trying out struts-chain -- I hope that you and others on the 
Struts' user list will share experiences about it and help us figure 
out how to move Struts to using it "out-of-the-box".

Joe

--
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Struts-Chain] how to use another chain for preprocessing?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Joe,

After skimming through WebWork2 (dirty word, huh?) chains to help figure out
Struts-Chains, I expected some blatantly obvious way to plug the chain name
into the action from the get-go.  After receiving email last night from
Craig, I now understand I should do that myself using the optional chain
name "servlet-complete-preprocess".  Until I received his letter, I believe
I was missing some blatant tie-in between the
org.apache.commons.chain.generic.LookupCommand chain segment and the Action
name or Action class.   Honestly, I assumed there would be new
action-mapping attributes such as chainPreProcess="chainName" and/or
chainPostProcess="chainName" to automatically invoke a chain before and/or
after the action invocation.  I now understand I need to make my own chain,
"servlet-complete-preprocess" would be a good place, to perform that
analysis in some way, manner, shape, or form.   If I continue down this
road, I could always join the developer list and submit a webapp example.
As for Struts-chains, I can clearly see the benefits for adding individual
steps into chains without having to replace the whole request processor.

Regards,
David

-----Original Message-----
From: Joe Germuska [mailto:Joe@Germuska.com]
Sent: Saturday, October 23, 2004 12:04 PM
To: Struts Users Mailing List
Subject: RE: [Struts-Chain] how to use another chain for preprocessing?


At 1:11 AM -0400 10/23/04, David G. Friedman wrote:
>I just don't (yet) see how or where you can set an action override. Am I
>supposed to add a chain called "servlet-complete-preprocess" and put my own
>code in to figure out what action is being invoked and somehow which chain
I
>want to call next?  I guess I was expecting something in the
>struts-config.xml via a set-property or something that easy to suggest
where
>or how to chain it.  I suppose this means I need more reading.  Can you
>suggest any links?

David:

There isn't a lot of existing doc for struts-chain.  This will be the
major task for making it the base request processor for a future
version of Struts.  Discussions like this will help us understand how
to explain it to people!

I'm not sure I understand exactly what you're trying to achieve.  Do
you have a case where you have significant control logic which
benefits from being broken out into "sub-chains"?  It would be
interesting to hear some more specifics about how people are thinking
of applying the chain model to Struts.

In any case, it would probably be a lot of redundant work to have
parallel chains that duplicate most of the logic flow in
"servlet-standard", so selecting an entire chain in
"servlet-complete-preprocess" may be the "wrong" place.  Depends on
how different your processes are.

In many cases, you could just add a few commands into
servlet-standard which inspect the request state contained in the
chain Context and which optionally perform behavior, rather than
duplicating the entire "servlet-standard" chain.

Of course, you could also replicate the "set default, then identify
sub-chain" type logic which happens in servlet-complete to configure
a bit of branching within servlet-standard, minimizing duplication,
but still providing some flexibility.

It may be because I'm conditioned to solving problems within the
standard Struts request processing sequence-of-events, but for my
first struts-chain based app, I simply added a few commands in the
main line, rather than configuring any kind of branching.

Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Struts-Chain] how to use another chain for preprocessing?

Posted by Joe Germuska <Jo...@Germuska.com>.
At 1:11 AM -0400 10/23/04, David G. Friedman wrote:
>I just don't (yet) see how or where you can set an action override. Am I
>supposed to add a chain called "servlet-complete-preprocess" and put my own
>code in to figure out what action is being invoked and somehow which chain I
>want to call next?  I guess I was expecting something in the
>struts-config.xml via a set-property or something that easy to suggest where
>or how to chain it.  I suppose this means I need more reading.  Can you
>suggest any links?

David:

There isn't a lot of existing doc for struts-chain.  This will be the 
major task for making it the base request processor for a future 
version of Struts.  Discussions like this will help us understand how 
to explain it to people!

I'm not sure I understand exactly what you're trying to achieve.  Do 
you have a case where you have significant control logic which 
benefits from being broken out into "sub-chains"?  It would be 
interesting to hear some more specifics about how people are thinking 
of applying the chain model to Struts.

In any case, it would probably be a lot of redundant work to have 
parallel chains that duplicate most of the logic flow in 
"servlet-standard", so selecting an entire chain in 
"servlet-complete-preprocess" may be the "wrong" place.  Depends on 
how different your processes are.

In many cases, you could just add a few commands into 
servlet-standard which inspect the request state contained in the 
chain Context and which optionally perform behavior, rather than 
duplicating the entire "servlet-standard" chain.

Of course, you could also replicate the "set default, then identify 
sub-chain" type logic which happens in servlet-complete to configure 
a bit of branching within servlet-standard, minimizing duplication, 
but still providing some flexibility.

It may be because I'm conditioned to solving problems within the 
standard Struts request processing sequence-of-events, but for my 
first struts-chain based app, I simply added a few commands in the 
main line, rather than configuring any kind of branching.

Joe
--
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [Struts-Chain] how to use another chain for preprocessing?

Posted by "David G. Friedman" <hu...@ix.netcom.com>.
Craig,

I just don't (yet) see how or where you can set an action override. Am I
supposed to add a chain called "servlet-complete-preprocess" and put my own
code in to figure out what action is being invoked and somehow which chain I
want to call next?  I guess I was expecting something in the
struts-config.xml via a set-property or something that easy to suggest where
or how to chain it.  I suppose this means I need more reading.  Can you
suggest any links?

Regards,
David

-----Original Message-----
From: Craig McClanahan [mailto:craigmcc@gmail.com]
Sent: Friday, October 22, 2004 9:39 PM
To: Struts Users Mailing List
Subject: Re: [Struts-Chain] how to use another chain for preprocessing?


The code that is in the repository now has focused on providing a
chain implementation that is fundamentally backwards compatible with
existing Struts 1.1/1.2 functionality.  As such, it emulates the
current RequestProcessor architecture by passng all requests through a
single commonly configured pipeline (which can, of course, be
customized).

Going beyond strict backwards compatibility, there's lots of options:

* A chain can already invoke another chain using the generic LookupCommand
  capability.  The "other" chain's name can be determined either
literally (via the
  "name" property) or indirectly (via the "nameKey" property, naming a
context
  property where some other processing logic has stored the name of the
chain
  to be executed).

* Given this, it would be trivial, for example, to create a chain equivalent
to
  the standard DispatchAction, which based the name of the chain to run on
some
  request parameter, or other incomding characteristic on the request.
  In the "servlet-standard" chain, this technique is used to execute a
  user-defined preprocess chain if there is one, ignoring it otherwise.

* Alternatively, it would be possible to set things up so that the name of
the
  action implicitly selects a correspondingly named chain (if there is one);
  defaulting to the standard chain if there is nothing special.  That way
you
  could customize the processing of individual actions without having to
  affect all of them.

* Regarding chaining of actions themselves, if you are using the standard
  request processing chain that remains as bad an idea as it has always
  been in Struts, and I don't see any reason to make it easier with chaining
  than it is today.  Instead, a different approach is likely to be better --
for
  example, building a chain that forwards to a view named "foo" could
  automatically look up a setup chain (specific to that view) and execute
  it if it's there.  This would likely eliminate many occurrences of the
"setup
  action --> view --> process action" design that you see in lots of
Struts code.

What a chain does is totally up to who designs the chain.  Once you
free yourself from a requirement to be backwards compatible (leaving
the existing servlet-standard chain there for people that *do* want
that), there's a lot of room to innovate.  So, the answer to nearly
all of yor questions is "yes, you can do that if you want to."

Craig


On Fri, 22 Oct 2004 20:23:28 -0400, David G. Friedman
<hu...@ix.netcom.com> wrote:
> I'm curious about Struts-Chain and have read through the 1.2.4 source on
it
> plus the 1.3 SVN repository.  I don't see anything suggesting how to make
my
> action chain itself to another action in the struts-config.xml example.
Nor
> do I see anything suggesting how to have an action be processed by a chain
> other than the default chain.  Is struts-chain supposed to be as one chain
> per web.xml pattern matching?  Are the chains supposed to do that and use
a
> common struts configuration object? (I.e. Just /do/whatever invokes chain
a
> but mapping /dothis/whatever3 invokes a different chain?
>
> Thanks for any help.
>
> Regards,
> David the Curious (humble@ix.netcom.com)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts-Chain] how to use another chain for preprocessing?

Posted by Craig McClanahan <cr...@gmail.com>.
The code that is in the repository now has focused on providing a
chain implementation that is fundamentally backwards compatible with
existing Struts 1.1/1.2 functionality.  As such, it emulates the
current RequestProcessor architecture by passng all requests through a
single commonly configured pipeline (which can, of course, be
customized).

Going beyond strict backwards compatibility, there's lots of options:

* A chain can already invoke another chain using the generic LookupCommand
  capability.  The "other" chain's name can be determined either
literally (via the
  "name" property) or indirectly (via the "nameKey" property, naming a context
  property where some other processing logic has stored the name of the chain
  to be executed).

* Given this, it would be trivial, for example, to create a chain equivalent to
  the standard DispatchAction, which based the name of the chain to run on some
  request parameter, or other incomding characteristic on the request.
  In the "servlet-standard" chain, this technique is used to execute a
  user-defined preprocess chain if there is one, ignoring it otherwise.

* Alternatively, it would be possible to set things up so that the name of the
  action implicitly selects a correspondingly named chain (if there is one);
  defaulting to the standard chain if there is nothing special.  That way you
  could customize the processing of individual actions without having to
  affect all of them.

* Regarding chaining of actions themselves, if you are using the standard
  request processing chain that remains as bad an idea as it has always
  been in Struts, and I don't see any reason to make it easier with chaining
  than it is today.  Instead, a different approach is likely to be better -- for
  example, building a chain that forwards to a view named "foo" could
  automatically look up a setup chain (specific to that view) and execute
  it if it's there.  This would likely eliminate many occurrences of the "setup
  action --> view --> process action" design that you see in lots of
Struts code.

What a chain does is totally up to who designs the chain.  Once you
free yourself from a requirement to be backwards compatible (leaving
the existing servlet-standard chain there for people that *do* want
that), there's a lot of room to innovate.  So, the answer to nearly
all of yor questions is "yes, you can do that if you want to."

Craig


On Fri, 22 Oct 2004 20:23:28 -0400, David G. Friedman
<hu...@ix.netcom.com> wrote:
> I'm curious about Struts-Chain and have read through the 1.2.4 source on it
> plus the 1.3 SVN repository.  I don't see anything suggesting how to make my
> action chain itself to another action in the struts-config.xml example.  Nor
> do I see anything suggesting how to have an action be processed by a chain
> other than the default chain.  Is struts-chain supposed to be as one chain
> per web.xml pattern matching?  Are the chains supposed to do that and use a
> common struts configuration object? (I.e. Just /do/whatever invokes chain a
> but mapping /dothis/whatever3 invokes a different chain?
> 
> Thanks for any help.
> 
> Regards,
> David the Curious (humble@ix.netcom.com)
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org