Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

chain of actions-advice

 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a situation of chain of Action classes.. I remember reading that its an inefficient way of doing it.

The situation is this ,

There is a page which lists an account details which can be modified and after they do the modification and click modify, they see their workspace with the list of accounts they work on.

I have an rendermodifyaction with modifyform bean which renders the prepopulated form
and when clicked modify the ModifyAction with modifyform bean does the modification and some
business logic calls.

I have a separate AccountListAction with accountlistform which renders the List of accounts

Everything works fine when separate. I am chaining Action to Action to collate this.

As follows

<action-mappings type="org.apache.struts.action.ActionMapping">
<action path="/modifyaction"
type="com.modifyaction"
validate="false">
<forward name="success" path="/AccountListAction.do" />
</action>
<action path="/AccountListAction "
type="com.AccountListAction "
scope="session"
validate="false">
<forward name="success" path="/result.jsp" />
</action>
</action-mappings>

Is this the right way and wot is the correct way to do the same
 
Pranav Sharma
Ranch Hand
Posts: 258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's best to avoid action chaining until really needed.

A better way to do the above would be to have a Base Action which implements the AccountsList logic. and let it be called whenever you want to list the accounts.
This way modify can call AccountsList if it needed it.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't look like you are using ActionForms... or at least if you are, they are not being controlled by the Struts framework because they are not specified in the ActionMapping. Since that is the case, I do not think you have an acceptable reason to chain Actions.

See, the benefit of Action Chaining to assist prepopulation is usually just a way to get around the fact that the Struts framework only allows one ActionForm in its control per ActionMapping. When navigating between two pages you often need two ActionForms - one for the page you are on and one for the page you are navigating to. And when you need two ActionForms in a single request (unless you create and save the forms to scope yourself, thus bypassing Struts' total control of ActionForms) you need two ActionMappings.

I anticipate that some developers will not share my views. Let the debates begin!
 
yash Vi
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use modifyform bean and Accountlistform bean.. it was just an example
of the action mapping given.I have many such situations in my project.Can you please explain the concept of Base Action class and how it can be implemented
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mannu means that you would create an Action class with a bunch of utility methods (which will be a base Action) and all of your current Action classes would then extend the base class instead of Action so they can use these methods internally.

I believe it would actually be better to place these methods in a separate class such as a Business Delegate.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic