I'm in the early phases of developing a brand spanking new site with Spring + Tiles. The site needs dynamically generated breadcrumbs.

What I mean by dynamic is that the user may reach a certain site from multiple starting points. If I have views for Customers, Orders and Products, the user could reach a Product directly:

Products -> Product xyz

or the user could reach a product through a customer's order:

Customers -> John Doe -> Orders -> Order 123 -> Product xyz

What is the best way to achieve breadcrumbs like these in a java environment? I've previously done this by using a request attribute (a Vector of Url objects) that is filled with the Urls in each action/servlet of my webapp (like in the action List of Products). I'm not happy with this solution as it requires adding code to each controller/action for generating the breadcrumb trail. And in a case like viewing a product of given order of given customer, the if-then-else logic needed to determine the trail is awful.

Are there any libraries that I could use?

+1  A: 

Why don't you just use a session variable that stores the trail? Each view would only have to either append itself to the variable or reset the variable in case of the 'root' views. The code to append it and the code to show it would always be the same and could go in a generic library, you just would call it with a flag to either append or reset the value in the case of storing the trail.

Vinko Vrsalovic
It's a nice idea, but the problem with this would be the case when a user is browsing the same site on multiple tabs (at least I hope users understand to do this)
In general, multiple tabs will each have their own session, depending on your web server.
Adam Tuttle

Struts2 has a breadcrumbs plugin.


That plugin is rubbish