Solved

Struts Actions

Posted on 2004-10-20
7
232 Views
Last Modified: 2013-11-24
Is there a way to call an Action from another Action class?
0
Comment
Question by:Flavaflav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 3

Expert Comment

by:sbockelman
ID: 12366187
well, you could just forward to it

0
 

Author Comment

by:Flavaflav
ID: 12366211
How can I forward it to another Action?
0
 

Expert Comment

by:sudhindra123
ID: 12366521
The execute method of the Action class in Struts returns an ActionForward where in the control can be forwarded (e.g. a JSP, Tile definition, Velocity template, or another Action). If the logical
mapping has been provided in the struts-config.xml file,you can use mapping.findForward(logicalname) or else you can also create a new ActionForward....
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Expert Comment

by:sbockelman
ID: 12369551
in struts-config, where you might normally have somethng like:

<action path="/EditProduct" type="com.cobite.exprts.chargeback.webapp.product.EditProductAction" name="ProductForm" scope="request" input="EditProduct">
      <forward name="view" path="EditProduct.jsp"/>
      <forward name="confirmation" path="ProductConfirmation.jsp"/>
</action>

you would just define the forward for another action using the url necessary:

<action path="/EditProduct" type="com.cobite.exprts.chargeback.webapp.product.EditProductAction" name="ProductForm" scope="request" input="EditProduct" >
      <forward name="view" path="EditProduct.do" />
      <forward name="confirmation" path="ProductConfirmation.do" />
</action>

Later versions of struts will even have a formal mechanism for implementing the "chain of responsibility" pattern, though I haven;t looked into it yet.

Usually, when someone has this question, the BETTER solution is to refactor some common code into a method that both actions can call (i.e., maybe put it into a base Action class from which you then subclass other Actions).  What exactly are you trying to do?

0
 

Author Comment

by:Flavaflav
ID: 12369973
I have TargetSelect.jsp which displays a summary of all exisiing Target objects and its properties in a table. This JSP also has a dropdown containing Target obj's that the user can select to add, modify or delete. TargetSelect.jsp needs to be accessed from 2 actions: DisplayTargetSelectAction which basically gets the Target[] from the db, puts it in the request obj, and forwards to TargetSelect.jsp. The other action is AddModifyTargetAction (called from AddModifyTarget.jsp), which of course adds a new Target or modifies the selected Target in the db and then (knowing that I can do this now) forwards to the DisplayTargetSelectAction. Do you think there's a better way to do this? Would it make more sense to combine all functionality into one Action class (DisplayTargetSelectAction)?

Btw, I need to display a confirmation message in TargetSelect.jsp if a Target has been successfully added or modified. Currently I attach a "message" String to the request obj in AddModifyTargetAction and use <bean:write> to display it. Can and should I use ActionMessages instead?
0
 

Author Comment

by:Flavaflav
ID: 12378217
The forwarding to another Action isn't working. This is what I have in struts-config.xml:

<action path="/DeleteTarget" type="com.ds.udecide.server.reporting.web.DeleteTargetAction" name="TargetForm" scope="session" validate="false"> <forward name="TargetSelectAction" path="DisplayTargetSelectPage.do"/></action>

In DeleteTargetAction I have:

return mapping.findForward("TargetSelectAction");

but it's not calling DisplayTargetSelectPageAction.

What am I doing wrong?
0
 
LVL 3

Accepted Solution

by:
sbockelman earned 75 total points
ID: 12382013
What IS it forwarding to, then?

Have you mapped the struts controller servlet to the *.do url pattern?

You may need to put a / in front of the path value, that is, try:

<forward name="TargetSelectAction" path="/DisplayTargetSelectPage.do"/>

I'm using Tiles, so my forwards are symbolic names, not real paths.  
My example was hastily copied/pasted, so I think maybe that would be the most likely issue.


0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 74
ejb entity bean example 2 54
passing enum to a method 4 47
Session in java desktop 5 34
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question