Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TILES and Logic

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Darryl A. J. Staflund
Ranch Hand
Posts: 312
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,
Try the links to "Tiles Advanced Features" on http://www.lifl.fr/~dumoulin/tiles/
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Junilu Lacar:
Gregg,
Try the links to "Tiles Advanced Features" on http://www.lifl.fr/~dumoulin/tiles/

Great! Got it. Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic