Solved

Struts Actions

Posted on 2004-10-20
7
228 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 128
ArrayIndexOutOfBoundException 9 68
Windows 10 and JDK 7 7u85 4 33
arguments to jar 5 15
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
This video teaches viewers about errors in exception handling.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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

16 Experts available now in Live!

Get 1:1 Help Now