You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Matt Raible <ma...@raibledesigns.com> on 2002/12/12 22:06:25 UTC

Action Organization (was: Action chaining)

I can't help chiming in as I'm in the midst of writing an example 
application using Struts for a Wrox book (Professional JSP 2.0).  On my 
last Struts application, I used LookupDispatchAction's for all my 
actions.  I basically organized it by entities, so that I had a 
UserAction, SearchAction, EventAction for the different types of 
activities.  This seemed to work pretty well, and each class had their 
respective CRUD details.

What Erik seems to be suggesting is having a handful of generic actions 
- so you end up with DeleteAction, SaveAction, etc. that maybe use 
reflection to figure out the entity to delete, save, etc?  Am I reading 
this correctly?  Sounds like a neat idea, and would probably work, 
unless you had to have custom business logic for the deletion of an 
entity.  For instance, when I delete a user, I need to delete all other 
entities associated with that user.  Hmmm, sounds like I might want to 
stick with my LDA architecture.  Thoughts?

Matt


On Thursday, December 12, 2002, at 01:43 PM, Andre Beskrowni wrote:

> just for the record, i'm in complete agreement with erik on this 
> issue.  i
> can remember reading warnings about how chaining actions isn't clean 
> design
> a long time ago.  and for a while i heeded those warnings.  but i 
> eventually
> found myself using the exact same pattern that erik mentioned when he
> started this discussion.  it's modular and clean.  if someone has a 
> better
> suggestion than:
> (1) call your delete action
> (2) forward to list action
> i'd like to see it, because it hasn't come up so far in this 
> discussion.
>
> i have to say, all of this "be careful" stuff seems a little dramatic. 
>  it
> seems the same admonishments could be used about writing methods 
> whenever
> you're using call-by-reference.
>
> ab
>
>> -----Original Message-----
>> From: Erik Hatcher [mailto:jakarta-struts@ehatchersolutions.com]
>> Sent: Thursday, December 12, 2002 2:02 PM
>> To: Struts Developers List
>> Subject: Re: Action chaining
>>
>>
>> Eddie Bush wrote:
>>> Erik Hatcher wrote:
>>>
>>>> There is no question that there are issues with forwarding
>> with form
>>>> population and such, and the known issue with multipart
>> data (which is
>>>> an isolated use-case anyway).
>>>
>>>
>>> The multipart issues exists regardless of whether you are
>> chaining or
>>> not - no?  I was of the impression that was the case.  The
>> single thing
>>> I see (and it's entirely possible I'm being short-sighted)
>> is that your
>>> form would be repopulated (which could be very evil to
>> track down if you
>>> hadn't already thought through the possibility of it happening).
>>> Redirecting avoids this issue altogether by causing another
>> request to
>>> be created.
>>
>> We're talking a little non-sequitor here.  Action chaining in
>> no way is
>> tied to whether I'm doing redirects or server-side forwards -
>> either are
>> possible with them.
>>
>> But you are absolutely correct about these issues.  I've not
>> encountered
>> them except with the multipart issue in a prior project.  I
>> don't modify
>> a form bean in these actions.  The only actions that modify a
>> form bean
>> in our system are the "setup" actions that populate a form prior to
>> forwarding to the JSP, and those would always be at the end
>> of a chain.
>>
>> Just to clarify - I'm not chaining tons of stuff together, just for
>> situations like I've mentioned.  Generally speaking I'm doing "text
>> book" Struts development, but I find that action chaining is
>> very handy
>> in certain situations, and I'm thankful that Struts actually
>> allows it
>> rather than forbid it altogether somehow.
>>
>> Its really just food for thought for the next architecture as
>> well as to
>> gather ideas from others on how they implement similar needs.
>>
>> 	Erik
>>
>>
>>
>>
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Action Organization (was: Action chaining)

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Matt Raible wrote:
> I can't help chiming in as I'm in the midst of writing an example 
> application using Struts for a Wrox book (Professional JSP 2.0).  On my 
> last Struts application, I used LookupDispatchAction's for all my 
> actions.  I basically organized it by entities, so that I had a 
> UserAction, SearchAction, EventAction for the different types of 
> activities.  This seemed to work pretty well, and each class had their 
> respective CRUD details.

Believe it or not, I am not using LookupDispatchAction at all in my 
current application (see the @author tags for a laugh).  And even 
when/if I have a need for it, I'll have to come up with some tricks (see 
previous discussions on this topic) to be able to use my custom 
BaseAction as the parent class yet still use LDA or LDA-like 
functionality under it.  All actions in our system must extend from 
BaseAction - it just gives us a finer level of control.

For the lookup table CRUD pages, all our lookup tables have good naming 
conventions, so I wrote some reflection based stuff that takes care of 
all tables in one action, and did a simplified LDA-like piece under the 
covers.  There is one JSP page for the list of all tables, one for the 
list of items where you choose to add/edit/delete, and one for 
editing/creating item detail - these service all tables.

> What Erik seems to be suggesting is having a handful of generic actions 
> - so you end up with DeleteAction, SaveAction, etc. that maybe use 
> reflection to figure out the entity to delete, save, etc?  Am I reading 
> this correctly?

No, not at all correct.  I have a Delete<whatever>Action and a 
List<whatever>Action... all specific to their function.  While a generic 
  DeleteAction could be done, it would require very good and strict 
naming conventions and would prevent compile-time checking.  While a 
global reflection-based scheme would be sort of slick, its not how I do 
it (except as mentioned above for the simple CRUD tables).

> unless you had to have custom business logic for the deletion of an 
> entity.

Exactly.  The example I gave was a simplified one, but fairly realistic. 
  But there are actions in our system which require a little logic, but 
typically not much.  Most actions are only a couple of lines of code - I 
use BeanUtils with custom registered Converters to make transferring 
VO's to/from form beans trivial and a one-line operation.

> For instance, when I delete a user, I need to delete all other 
> entities associated with that user.

Cascading deletes?!  :)


> Hmmm, sounds like I might want to 
> stick with my LDA architecture.  Thoughts?

Seems reasonable - you have a scheme you like and works well for you. 
Thankfully Struts allows us all to have our own ways of doing things and 
they all work.  But that is a negative also... too many ways to do 
things and not a lot of best practices.  I've recently gotten two of the 
new Struts books: Sam's Struts Kick Start and Manning's Struts in Action 
(thanks to James, Kevin, and Ted and Craig et al for their hard work - I 
know what it takes now, and I respect those that endure authoring that 
much more now!).  These books all have their own ways of doing things.

Now if I was to inherit or be called into a job with an existing large 
Struts app, I'd likely scream at the practices I see going on as it 
would differ dramatically from what I like :)

	Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Action Organization (was: Action chaining)

Posted by "V. Cekvenich" <vc...@basebeans.com>.
If you say it this way then... this is what I do, in case I did not make 
it clear:

I have a baseAction (of course).
The concrete actions, for example UserAction has {
onDelete(){}
onSave(){}
onDisplayList() {}
onInsert() {}
}
The baseAction dispatches execute event.

In some cases those events go to the super class, if they are simple. 
But at least I have palace to do custom processing for that one thing 
(as well as having a place for generic processing in base).
Above I think is implied in the Husted book.

I think having a standard DeleteAction is not as good.

.V

Eddie Bush wrote:
> Naw - I think what he's saying is that, like you'd have a showUsers 
> which would populate a userForm, then you'd have, say ... createUser, 
> readUser, updateUser, deleteUser.  Your deleteUser would then chain back 
> to showUsers so the list could be viewed again.  At least ... I think 
> that's kind of what is being discussed :-)  You're over-generalizing I 
> believe, Matt ;-)  You've got a nifty though, but I'd think it would be 
> a big PITA to implement.
> 
> Matt Raible wrote:
> 
>> I can't help chiming in as I'm in the midst of writing an example 
>> application using Struts for a Wrox book (Professional JSP 2.0).  On 
>> my last Struts application, I used LookupDispatchAction's for all my 
>> actions.  I basically organized it by entities, so that I had a 
>> UserAction, SearchAction, EventAction for the different types of 
>> activities.  This seemed to work pretty well, and each class had their 
>> respective CRUD details.
>>
>> What Erik seems to be suggesting is having a handful of generic 
>> actions - so you end up with DeleteAction, SaveAction, etc. that maybe 
>> use reflection to figure out the entity to delete, save, etc?  Am I 
>> reading this correctly?  Sounds like a neat idea, and would probably 
>> work, unless you had to have custom business logic for the deletion of 
>> an entity.  For instance, when I delete a user, I need to delete all 
>> other entities associated with that user.  Hmmm, sounds like I might 
>> want to stick with my LDA architecture.  Thoughts?
>>
>> Matt 
> 
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Action Organization (was: Action chaining)

Posted by Eddie Bush <ek...@swbell.net>.
Naw - I think what he's saying is that, like you'd have a showUsers 
which would populate a userForm, then you'd have, say ... createUser, 
readUser, updateUser, deleteUser.  Your deleteUser would then chain back 
to showUsers so the list could be viewed again.  At least ... I think 
that's kind of what is being discussed :-)  You're over-generalizing I 
believe, Matt ;-)  You've got a nifty though, but I'd think it would be 
a big PITA to implement.

Matt Raible wrote:

> I can't help chiming in as I'm in the midst of writing an example 
> application using Struts for a Wrox book (Professional JSP 2.0).  On 
> my last Struts application, I used LookupDispatchAction's for all my 
> actions.  I basically organized it by entities, so that I had a 
> UserAction, SearchAction, EventAction for the different types of 
> activities.  This seemed to work pretty well, and each class had their 
> respective CRUD details.
>
> What Erik seems to be suggesting is having a handful of generic 
> actions - so you end up with DeleteAction, SaveAction, etc. that maybe 
> use reflection to figure out the entity to delete, save, etc?  Am I 
> reading this correctly?  Sounds like a neat idea, and would probably 
> work, unless you had to have custom business logic for the deletion of 
> an entity.  For instance, when I delete a user, I need to delete all 
> other entities associated with that user.  Hmmm, sounds like I might 
> want to stick with my LDA architecture.  Thoughts?
>
> Matt 

-- 
Eddie Bush




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>