Breadcrumbs

No, the library does not actually contain a breadcrumbs component. The layout is too application specific for a general component to be useful.
However it is very easy to create your own breadcrumbs component, based on the t5navigation services.

You can decide the number of items to be included in the breadcrumbs by including the following in your applicatin module class.


public static void contributeApplicationDefaults( MappedConfiguration<String, String> configuration )
{
configuration.add( NavigationConstants.NAVIGATION_RETURN_CACHE_SIZE, "5" );
}

If you don't configure anything, up to five items will be included.

You define a template for your breadcrumbs component. You can go wild and use any layout and style you prefer, but it can be as simple as he following.


<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<fieldset>
<legend>breadcrumbs</legend>
<ul>
<t:loop source="breadcrumbs" value="current" index="index">
<li><t:actionlink t:id="breadcrumb" context="index">${current.title}</t:actionlink></li>
</t:loop>
</ul>
</fieldset>
</div>

The code which is needed to make this work, looks like this.


package mayapp.components;

import org.equanda.t5nav.services.NavigationTarget;
import org.equanda.t5nav.services.NavigationContext;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ApplicationStateManager;
import org.apache.tapestry5.annotations.Property;

/**
* Component which displays the breadcrumbs
*/
public class Breadcrumbs
{
@Inject
private ApplicationStateManager asoManager;

@Property
private NavigationTarget current;

@Property
private int index;

public NavigationTarget[] getBreadcrumbs()
{
if ( !asoManager.exists( NavigationContext.class ) ) return null;
NavigationContext currNav = asoManager.get( NavigationContext.class );
return currNav.getRecentReturnTargets();
}

public Object onActionFromBreadcrumb( int index )
{
NavigationContext currNav = asoManager.get( NavigationContext.class );
if ( null == currNav ) return null;
return currNav.getRecentReturnTargets()[index].getLink();
}
}
  • 1. Breadcrumbs