I am using Tiles with Struts. I have used the tiles definition xml files to generate the JSP pages. For eg. I have a JSP called timesheet.jsp which I have defined in the tilesDefinition.xml file. This definition name is then referenced in the struts-config.xml. Upto this everything is fine. Now I have a submit button in this jsp, which calls the corresponding action, which forwards to a success page or a error page. When it is forwarded to a error page, my problem is how to make a HREF to go back to the timesheet page. As this JSP page is being built by parsing the tileDefinitions.xml file, the only reference I have of this JSP page is the name in the tileDefinitions.xml file's definition tag. I am not able to figure out how to make this a HREF to the timesheet.jsp. I tried the html:link tag's forward attribute and gave the referenced name here. But it didn't work. Please help me that how I can do that. Thanks in advance
The only thing I can think of is to have your error page submit back to a *.do that expects a parameter that can be used to forward to Tiles. That is, sometime during the processing of the action and before forwarding to the error page, use request.setAttribute() to save the "link" back to the source page. The error.jsp extracts that "link" using request.getAttribute() in a jsp scriplet and saves its value as a hidden field in the error page. When the client exits the error page by clicking on a submit button, the link value is submitted as well and the receiving action can simply forward to Tiles with a new ActionForward that has its path equal to the link value. Haven't actually tried this but it seems to work in my head... give it a whirl and see if it's doable (I'll probably try to do this on my own Tiles/Struts app soon and it will be nice if you could be my guinea pig ). [ February 01, 2003: Message edited by: Junilu Lacar ]
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Originally posted by Rich Smyth: A similar problem: Is there a struts Action that will forward to the page that contained the ActionForm or the link that triggered the action? ...how can I get the action to forward "back" to the original page?
try ActionMapping.getInput() or getPath() Again, linking only to Actions will simplify your life. If your Action forwards to another Action, then you can simply put the value of ActionMapping.getInput() or getPath() as an attribute in the request or session. The target Action can then extract the value of that attribute and set the appropriate form field, which can then be put into the target JSP either as an href, a form action, or a hidden field.
Joined: May 30, 2002
If your Action forwards to another Action, then you can simply put the value of ActionMapping.getInput() or getPath() as an attribute in the request or session.
If in my config I have
and in my JSP I have
then within my CounterAction class, mapping.getPath() returns "/increaseCount" and mapping.getInfo() returns null. I don't see how either value will help me return to my original page. What am I missing ? Rich
In any Action that eventually displays a JSP that links to CounterAction, you'd do something like this: // perform() or execute() request.setAttribute("counter.caller", mapping.getPath()); In the JSP displayed by the Action: <html:link forward="increaseCount" paramId="caller" paramName="counter.caller" >link to increaseCount forward</html:link> which would render: <a href="/increaseCount.do?caller=getPath() value">link to increaseCount forward</a> In whatever jsp is displayed by CounterAction, you would put this: <html:link page='<%= request.getParameter("caller") + ".do" %>'>back to caller</html:link>
NOTE: If you're using Tiles, i.e., the forward path is a Tiles definition name, there might be a problem with the substitution of the forward path value. This should work with just Struts paths though, which is what your configs appear to be doing. [ February 10, 2003: Message edited by: Junilu Lacar ]
Joined: May 30, 2002
When I reread your earlier post I now unsderstand what you were saying. I was barking up the wrong action so to speak. The current.page attribute has to be set before the counter action is executed NOT set upon entry to the counter action - big difference. Now that that issue is all cleared up. The joke is that I am converting to tiles! :-) Thanks for your advice. Rich
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com