Solved

Struts Actions

Posted on 2004-10-20
7
233 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
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…

688 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