aspose file tools*
The moose likes Struts and the fly likes Problem with calling IncludeAction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with calling IncludeAction" Watch "Problem with calling IncludeAction" New topic
Author

Problem with calling IncludeAction

Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
How do I include output from another Action class into existing Action class?

Here are code excerpt from struts-config.xml:

<action path="/dgrT20Jap"
type="org.apache.struts.actions.IncludeAction"
name="appForm"
parameter="/dgr.do"
scope="request"
validate="false"/>

How do I call this mapping from my class?

This doesn't work: mapping.findForward("dgrT20Sgr");
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Im not sure, but it sounds like what you're trying to do is "chain" actions, or have one action forward to the other action. There is a section in the Struts user documentation that explains how to do this.

See:
http://struts.apache.org/faqs/newbie.html#chaining

However, many Struts practitioners feel that chaining actions together is bad form. My suggestion would be to take a good look and see if there are other design alternatives to having one action call another before presenting the jsp. If the chaining option still seems the cleanest, then go ahead and do it, in spite of the flak you may get from Struts purists.

Merrill


Merrill
Consultant, Sima Solutions
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
No, I don't want chaining. I just want to call some other action, get the job done (return null and than get back to the first action.

I'm just interested in how I can use include inside Action class. I know how to do that inside JSP but currently I'm not able to do it inside Action. Any example?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I don't see a parallel between using an include in a jsp and some sort of include function in a struts action class. In a JSP, the point of an include is to be able to write a portion of the page (Headings, data table, footings, etc.) that other pages can draw on to produce a complete page.

The purpose of an action class is not to produce a page, but to use model objects to prepare the data, and then forward to to he appropriage page. I don't see how the concept of an include fits in here at all.

If you have logic that needs to be shared by multiple action classes, the best way to do this would be to put this logic in some sort of utility class. When an action needs this logic, it simply instantiates the utility class and uses it.
Nikhil Menon
Ranch Hand

Joined: Nov 22, 2004
Posts: 70
I'm just interested in how I can use include inside Action class. I know how to do that inside JSP but currently I'm not able to do it inside Action. Any example? Originally Posted by : Velika Srbija


I think what Velika Srbija meant was in jsp, include action <jsp: include/> and not include directive <%@ include %>.
If this is the case then

If you have logic that needs to be shared by multiple action classes, the best way to do this would be to put this logic in some sort of utility class. When an action needs this logic, it simply instantiates the utility class and uses it. Originally Posted by : Merrill Higginson


Would certainly fits your requirement.

[ February 23, 2005: Message edited by: Nikhil Menon ]
[ February 23, 2005: Message edited by: Nikhil Menon ]
Velika Srbija
Ranch Hand

Joined: Jan 15, 2002
Posts: 172
Have look at this thread:

Rendering of Servlet output

... you'll get the point.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with calling IncludeAction