It's not a secret anymore!*
The moose likes Struts and the fly likes TILES and Logic 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 "TILES and Logic" Watch "TILES and Logic" New topic
Author

TILES and Logic

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

What is the best way to handle logic using TILES. For example, say I had a page set up that included a Header, SubHeader, Body, and Footer.
The SubHeader should either display prompts for a login, or a welcome message for the logged in user.
Where should the logic be performed to determine which SubHeaer should be displayed?
Thanks.
BTW - I am very new to STRUTS and TILES to don't laugh at my ignorance.
[ June 02, 2003: Message edited by: Gregg Bolinger ]

GenRocket - A Test Data Generation Platform
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
What I tend to do is create a number of different tile definitions in the tiles-def.xml file. Once you do this and give each tile a name, you can use the struts-config.xml to forward a mapping to the definition instead of a JSP page.
For example, say my tiles-def.xml looks as follows:

Then I could forward an action to one of the tile definitions as follows:

In this way, you really don't need to worry about tile-substitution logic. Just subclass your tile definitions and invoke them using your struts-config.xml file.
Cheers,
Darryl
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
I second Darryl's approach, it makes for much cleaner JSP pages then explicitly using the tiles taglibs in each page (which is the other widely used approach). Of course this comes with a tradeoff, every JSP page must have a corresponding tile definition. However, considering the ease of writing a tile definition, I don't see it as a very big problem.
Check out this article from TheServerSide for a more detailed example: Tiles 101/201.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

We use something similar to the above approach only we have extracted everything that has to do with display to the tiles-def.xml. We make use of nested tiles and we have our definitions set up so that we can specify different titles, menus, menu items, sub-menus, headers, footers, and bodies as we please. The only things we have in the struts-config.xml are forwards to tiles definitions.
I'm in the middle of a long and busy testing/debugging phase right now (when will the waterfall life-cycle ever die out? ) but as soon as I have some breathing room, I hope to be able to share what we have done in a future JavaRanch newsletter article.
My tip for the day: Did you know that you can include a Struts action?
<jsp:include page="myAction.do">
<jsp:param name="p1" value="test" />
<jsp:param ... />
</jsp:include>
This works like a tile too. I used this to factor out different summary tables that we wanted to show on personalized welcome pages. This really helps to keep JSPs smaller and less cluttered and the different section logic separate from each other.
[ June 03, 2003: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Chris Mathews:
I second Darryl's approach, it makes for much cleaner JSP pages then explicitly using the tiles taglibs in each page (which is the other widely used approach). Of course this comes with a tradeoff, every JSP page must have a corresponding tile definition. However, considering the ease of writing a tile definition, I don't see it as a very big problem.
Check out this article from TheServerSide for a more detailed example: Tiles 101/201.

That ServerSide article was the best one I have seen so far.
They gave a link to some documentation that the creator of Tiles wrote, but the link appears to bed dead. Does anyone have that PDF?
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Cool. The Tiles controller class actually works pretty much the same way as my jsp:include Action.
You learn something new every day
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4419
    
    5

Gregg,
Try the links to "Tiles Advanced Features" on http://www.lifl.fr/~dumoulin/tiles/
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Junilu Lacar:
Gregg,
Try the links to "Tiles Advanced Features" on http://www.lifl.fr/~dumoulin/tiles/

Great! Got it. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TILES and Logic
 
Similar Threads
struts validator and tiles
Populating a Dropdown Box
Creating dynamic titles
Tiles or sitemesh for struts ?
Frames in Tiles