Cal VA
Weblog  
 
September 2010
S M T W T F S
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
<Aug Today Oct>
Search
Topics
Personal Personal
Java Java
Syndicate
Links
Referrers Today
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
   
 
 
 
 
 
 
 
   
 
 
 
 
 
God Bless America
 

The Posting
Friday, July 11, 2003 Building Bread Crumbs with Tiles and Struts

Let me preface this with the facts: i am not very technical so there are probably many out there that can do what i am demonstrating in a 'better' manner. I used the ideas from the Tiles creator himself - Cedric Dumoulin (thanks for a great tool) and his advanced manual to create my site. This is a small part of the site demonstrating the use of bread crumbs and Tiles. I love Tiles and probably tend to over use the framework. You will need to download the Crumb.war

There are two techniques used in this app for bread crumb generation. The first is to write a Tiles Action that accesses the Tiles definition and the second is a tag that reads the tiles definition. Both have advantages. Using the Tiles Action you can extend the functionality of the class to provide additional Tiles based services. Using the tag is super easy and reduces the overhead of an additional action class.

The three crumb bars on each page display - from the top - the Tiles Action technique, the default (almost - style class added) crumb tag and the third the crumb tag with a different style class and separator. You have probably already clicked about a figured out how they work - but let me describe the Tiles Action first.

The Tiles Action is triggered by adding a controllerUrl attribute to the definition - in this case i am using controllerUrl="/do/renderCrumb". renderCrumb extends Tiles Action and is called whenever the corresponding Tiles Definition is triggered - this includes any controllerUrl that is in a parent definition. Since i attached the controllerUrl to my base definition it will be called for each page (I only link to definitions). Anyway in the renderCrumb action the Tiles Component Context is read giving us access to the current definition - including all the inherited definitions. So the crumb attributes are accessed as well as the page name attribute. This depends on the crumb link and title attributes following a specific naming convention. Each level of the site must inherit it's definition from it's parent and add a set of crumb attributes incrementing the level number on the end of the attribute.

In the Crumbs Action i extended the ability of the Tiles Action to read and load another attribute (of course this is pretty easy to get directly in the jsp as well). This allows some menu styling based on the current Tiles definition. Some additional things you can do in a Tiles Action is play with the definition - change an attribute or even change the template. For an example of this go to my personal site settings page. Here i change the master template used and the stylesheet based on the user's selection.

Tiles Actions are pretty handy - if you select the portal view each of the little list boxes on the right side of the screen are individual jsps with their own action classes. This allows to each to be used on any jsp and the Action Class for the jsp does not need to know the other tile is there. The little tile can load it's own beans without depending on the page it is included in. Additionally i am using osCache to cache the portal tiles since executing 6 or 7 Action Classes per page is a bit much. The support projects page has all the support projects i am using.

The Tiles Action version displays the root (home) crumb but the Crumb Tag does not - you can modify both. The Crumb Tag needs no attributes if you name your crumb link and title crumblink and crumbtitle. If you are inclined you can change the style, separator character, and names of the crumb attributes in the Tiles definition.xml.

The only "bad" part of all this is - you need to use tiles for your site layout in a structured manner. This may make this technique not right for your site. You could get the crumb definitions from another source in the Tiles Action using a page attribute as a key to a database or xml file.

Again - none of this is original, Cedric provided the code for the Tiles Action and Steve Melzer wrote the tag which i extended.

posted at 0948 hrs



 
 
What's New
02/14 Baileys
02/07 Slideshow
10/20 Wyoming Vaca...
03/30 Mom and Dad ...
11/15 Cal Holman P...

New Pics
No New Pictures

Popular Pics
1 Baileys and Sweet...
2 Sweetpea and a Mo...
3 Sleepy
4 Vacation in Highl...
5 A Christmas Jacket
6 Washington Hall -...
7 42nd Street Subway
8 Sunrise in Manhattan
9 Little Post Office
10 Radio City at Chr...
11 Dinner in Monteverde
12 Sunrise in Manhattan
13 I Can't Believe Y...
14 Salis IT
15 Cozy Fire

Top Page Hits
1 GuestBook
2 ScrapbookSearch
3 blogging
4 SupportProjects
5


    Top Top    
java struts tomcat log4j DTDns MySQL Ant Apache