• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TILES and Logic

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 314
2
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gregg,
Try the links to "Tiles Advanced Features" on http://www.lifl.fr/~dumoulin/tiles/
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Lookout! Runaway whale! Hide behind this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic