Solved

Struts Actions

Posted on 2004-10-20
7
227 Views
Last Modified: 2013-11-24
Is there a way to call an Action from another Action class?
0
Comment
Question by:Flavaflav
  • 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
The viewer will learn how to implement Singleton Design Pattern in Java.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now