File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts / Tiles - changing which layout is used at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts / Tiles - changing which layout is used at runtime" Watch "Struts / Tiles - changing which layout is used at runtime" New topic

Struts / Tiles - changing which layout is used at runtime

will gillingham

Joined: Jun 28, 2010
Posts: 2

(using struts 1.3.8)

I've written some form pages. The forms are generated by actions and appear in my final rendered page via a Tiles 'content' section. Now, I want to make the form AJAX enabled (while keeping the underlying non-ajax functionality). I think I have a handle on how that will work... my problem is, I want to reuse the actions that are currently generating the Tiles 'content' element (my simple 'AJAX' process: user clicks a submit button, I use javascript to send the request to the server, get back JUST THE CONTENT section and update my innerHTML (or whatever) with that text). - But my actions are tied to a layout that displays a header/footer/menu/etc... I want just the content - which is what my action is generating.

I've done some testing and can call the actions via javascript (AJAX) - and I'm able to pass an additional parameter (AJAX=1 - not that I expect that to do anything - I just know I have a switch available)... but what is returned to me is the entire page (as I expect - but don't want!).

I really don't want to write an entire new set of actions - to tie them to a simplified layout (i.e. just the 'content')

Ideally, I'd like to be able to determine (within my action code) which layout to use... but I fear it is too late in the process to do that.

My actions are tied to the Tile/layout by (I think) my (i believe this may be part of the problem/solution) - below are 2 of my a action definitions:

This is my tile/layout definition:

If I could just override that "extends='layout_b'" with (something like) "extends='contentOnlyLayout'" at runtime, based on my switch AJAX=1

I'm new to Struts and Java... hope I'm making some sense!


bill g
Richard Golebiowski
Ranch Hand

Joined: May 05, 2010
Posts: 213

First, if you are new to Struts why are you leasrning an old version and not the latest version?

As to your problem, no, you cannot do an override.

From what I can gather about your question it looks like you want to submit the form but then only have the "content" tiles section refreshed. If that's what you want to do then you need to make if so your content, gymMaintenance.jsp, can be refreshed using AJAX. That will be the only way you can change the content only.
will gillingham

Joined: Jun 28, 2010
Posts: 2
Ok - so there is a solution. First, I had to change my struts config to NOT associate the page with a layout/template. Next, I had to create a stub jsp file that would examine my parameter 'AJAX=1' - depending on the value, the stub file chooses the definition:


My actions now point to the stub page (gymMaintenanceStub.jsp) and each of the above mentioned tile definitions point to my original jsp page for their content section:

Everything works fine - validation, ActionForm is accessible... there was no further work needed on the server.


bill g
I agree. Here's the link:
subject: Struts / Tiles - changing which layout is used at runtime
jQuery in Action, 3rd edition