File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Struts + Tiles + Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts + Tiles + Form" Watch "Struts + Tiles + Form" New topic
Author

Struts + Tiles + Form

Paul Woods
Greenhorn

Joined: Nov 15, 2002
Posts: 23
Hi Everyone, I have been using struts a little bit, and thought I had a handle on it. I have started using Tiles, and am having a problem understanding how to correctly use forms inside of tiles.
If I have a form that appears across multiple 'pages', as a tile that is re-used, how do I accomplish that in an appropriate manner? I am considering validation, and how to specify the action forms input page in the struts-config.xml file.
When the user enters bad data, I want to return the error to the *page* they were at when they entered that data. Re-using the form on different pages though, I can only specify one input page in the struts config.
Thanks to anyone that can set me straight.
Paul
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
One way of doing this that comes to mind is to code the Tile containing the HTML form in such a way that it submits the form to a Struts Action of type RelayAction. By using this action class to relay the request to another more specific action based on the value of the 'dispatch' attribute in the request header, you can then code the names of the error pages in these more specific actions.
For instance, suppose I have a tile T1 which is included by two tile definitions TD1 and TD2. T1 defines an HTML form that submits its content to a action.
When T1 is rendered by TD1, it submits its form to:

When T1 is rendered by TD2, it submits its form to:

The "/processForm" action to which these forms are submitted would appear somewhat as follows in the struts-config.xml file:

You would then define the "/processTD1Form" and "/processTD2Form" actions in the struts-config.xml and have them take on the responsibilities of processing the form and specifying the tile definition that should be returned in case of an error.
This doesn't feel like the optimal solution to your question but I think it should work if you don't mind relaying your form submissions through a RelayAction definition.
Hope this helps.
Darryl
[ April 25, 2003: Message edited by: Darryl A. J. Staflund ]
[ April 25, 2003: Message edited by: Darryl A. J. Staflund ]
Paul Woods
Greenhorn

Joined: Nov 15, 2002
Posts: 23
Thanks Darryl, that looks like a good solution to me, taking the input parameter into account.
I just discovered though that if I ignore the input parameter, and do validation in the action class, it gets significantly easier.
As I have a unique action calling each definition, I can set a session attribute describing which definition was just called. In the struts-config, for that common form, I then set unique forwards for each possible definition that contains it, such as:

In the action mapping for the form, I then just reference that session attribute, and call it as

I don't know if the above is considered acceptable or not, but it seems to work. Thanks again,
Paul
[ April 25, 2003: Message edited by: Paul Woods ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts + Tiles + Form
 
Similar Threads
General question Struts and Tiles
how to translate form data using i18n
Can we use other result types when using Tiles
Struts & Tiles frame work issue
The old mutliple pages submit to one action problem...