[jboss-user] [JBoss Seam] - Re: Breadcrumbs within the same conversation / pageflow

ngeadah do-not-reply at jboss.com
Sun Oct 8 11:45:38 EDT 2006


Here is the solution.  This creates a clickable breadcrumb trail as the user moves through the pageflow.  The breadcrumb trail gets correctly adjusted if the user goes back.

1- A page action mapped to "*" in pages.xml


  | <pages>
  | 
  |    <page view-id="*" action="#{breadcrumb.log}"/>
  | 
  | </pages>
  | 

2- A "breadcrumb" Seam component:


  | @Name("breadcrumb")
  | public class BreadcrumbHandler {
  | 	private List<Page> conversationCrumb;
  |  
  | 	public void log() {
  | 		try {
  | 			if (Contexts.isConversationContextActive()) {
  | 			conversationCrumb = (List) Contexts.lookupInStatefulContexts("conversationCrumb");
  | 			if (null == conversationCrumb) conversationCrumb = new LinkedList<Page>();
  | 			if (null != Pageflow.instance()) {
  | 				if (null != Pageflow.instance().getPage()) {
  | 					Page thePage = Pageflow.instance().getPage();
  | 					if (conversationCrumb.contains(thePage)) {
  | 						// rewind the conversation crumb to where the page is
  | 						conversationCrumb = conversationCrumb.subList(0, conversationCrumb.indexOf(thePage)+1);
  | 					} else {
  | 						conversationCrumb.add(thePage);
  | 					}
  | 				}
  | 				Contexts.getConversationContext().set("conversationCrumb",conversationCrumb);
  | 				}
  | 			} else {
  | 				Contexts.removeFromAllContexts("conversationCrumb");
  | 			}
  | 		} catch (Throwable t) {
  | 			// Do nothing as this is just a "listener" for breadcrumbs
  | 			t.printStackTrace();
  | 		}
  | 	}
  | 	
  | 	public void navigate()
  | 	{
  | 
  | 		FacesContext context = FacesContext.getCurrentInstance(); 
  | 		Map map = context.getExternalContext().getRequestParameterMap();
  | 		String viewId = (String) map.get("viewId");
  | 		String pageName = (String) map.get("name");
  | 
  | 		Pageflow.instance().reposition(pageName);
  | 		
  | 		Redirect redirect = Redirect.instance();
  | 		redirect.setViewId(viewId);
  | 		redirect.execute();
  | 		
  | 	}
  | }
  | 
  | 

3- JSF tags needed to display the crumbs.  This relies on the h:commandLink which creates Javascript, but it's probably pretty easy to change this to an s:link instead (although s:link won't take paramaters until the Seam 1.1 release).  Also, I wish I could print out the page description instead of the page name, but Seam has a bug when calling getDescription on a page (http://jira.jboss.com/jira/browse/JBSEAM-272)


  |   <t:dataList value="#{conversationCrumb}" var="crumb">
  |     <h:outputText value=" | "/> 
  | 	<h:commandLink action="#{breadcrumb.navigate}">
  | 		<f:param name="viewId" value="#{crumb.viewId}"/>
  | 		<f:param name="name" value="#{crumb.name}"/>
  | 		<h:outputText value="#{crumb.name}"/>
  | 	</h:commandLink>
  |   </t:dataList>
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3976824#3976824

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3976824



More information about the jboss-user mailing list