Announcement Announcement Module
Collapse
No announcement yet.
BreadCrumbs in Spring Web Flow Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BreadCrumbs in Spring Web Flow

    I have implemented Breadcrumbs in Spring Web Flow using BreadCrumbListener

    ------->


    package com.tcs.breadcrumb;

    import java.util.LinkedList;


    import org.apache.log4j.Logger;
    import org.springframework.webflow.core.collection.Mutabl eAttributeMap;
    import org.springframework.webflow.definition.FlowDefinit ion;
    import org.springframework.webflow.definition.StateDefini tion;
    import org.springframework.webflow.execution.FlowExecutio nListenerAdapter;
    import org.springframework.webflow.execution.FlowSession;
    import org.springframework.webflow.execution.RequestConte xt;
    import org.springframework.webflow.execution.View;

    /**
    * Listener to handle breadcrumb navigation.
    *
    * @author Jeroen Wolsink
    *
    */
    public class BreadCrumbListener extends FlowExecutionListenerAdapter {

    private static final Logger LOG = Logger.getLogger(BreadCrumbListener.class);

    private static final String CONTEXT_KEY = "trail";

    @SuppressWarnings("unchecked")
    @Override
    public void sessionStarting(RequestContext context, FlowSession session, MutableAttributeMap input) {

    FlowDefinition flowDefinition = session.getDefinition();

    LOG.debug("Starting session for: " + flowDefinition.getId());

    // New flow session is initiated, so store trail in context

    LinkedList<BreadCrumb> trail = (LinkedList<BreadCrumb>) context.getConversationScope().get(CONTEXT_KEY);
    if (trail == null) {
    trail = new LinkedList<BreadCrumb>();
    context.getConversationScope().put(CONTEXT_KEY, trail);
    }

    }

    @SuppressWarnings("unchecked")
    @Override
    public void viewRendering(RequestContext context, View view, StateDefinition state) {
    super.viewRendering(context, view, state);

    LinkedList<BreadCrumb> trail = (LinkedList<BreadCrumb>) context.getConversationScope().get(CONTEXT_KEY);

    if (trail != null) {

    // Create new breadcrumb
    BreadCrumb breadcrumb = new BreadCrumb(state.getId(), state.getId());
    trail.add(breadcrumb);
    if (trail.contains(breadcrumb)) {
    // Breadcrumb already exists in trail. Erase succeeding breadcrumbs.

    int pos = trail.indexOf(breadcrumb);
    trail.subList(pos + 1, trail.size()).clear();
    LOG.debug("Succeeding breadcrumbs erased");
    } else {
    // Add new breascrumb to trail.
    trail.add(breadcrumb);
    LOG.debug("Breadcrumb added to trail");
    }
    } else {
    LOG.error("Breadcrumb trail not found in context");
    }
    }

    }




    BreadCrumbs class----->

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package com.tcs.breadcrumb;



    import java.io.Serializable;

    /**
    * Breadcrumb value holder containing the viewState identifier and label. The viewState identifier is used by Spring
    * Webflow to navigate to the defined view. The label can be used as displaylabel, to give the breadcrumb a more
    * meaningful name.
    *
    * @author Jeroen Wolsink
    *
    */
    public class BreadCrumb implements Serializable {

    private String viewState;

    private String label;

    /**
    * Constructor
    *
    * @param viewState The viewState
    * @param label Display label
    */
    public BreadCrumb(String viewState, String label) {
    this.viewState = viewState;
    this.label = label;
    }

    /**
    * @return viewState
    */
    public String getViewState() {
    return this.viewState;
    }

    /**
    * @param viewState viewState
    */
    public void setViewState(String viewState) {
    this.viewState = viewState;
    }

    /**
    * @return label
    */
    public String getLabel() {
    return this.label;
    }

    /**
    * @param label label
    */
    public void setLabel(String label) {
    this.label = label;
    }

    @Override
    public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((this.viewState == null) ? 0 : this.viewState.hashCode());
    return result;
    }

    @Override
    public boolean equals(Object other) {
    if (this == other) {
    return true;
    }
    if (!(other instanceof BreadCrumb)) {
    return false;
    }
    BreadCrumb Breadcrumb = (BreadCrumb) other;
    return this.viewState.equals(Breadcrumb.viewState);
    }

    }


    It works and i can track my flows
    in jsp

    But my problem is providing links to breadcrumbs. If I give a url that calls a flow after getting resolved in dispatcherServlet(e.g.- home.htm or loginPage.htm). My conversation scope variable is reset..

    What i mean is,i have somthing like this
    home---->nextFlow---->loginFlow
    as bread crumbs
    if I click on nextFlow
    the link works but breadcrumbs show

    nextFlow

    only rather than

    home---->nextFlow


    Please help
    Last edited by saurabhsolutions; Jun 1st, 2011, 02:00 AM.

  • #2
    http://forum.springsource.org/showth...ht=BreadCrumbs


    got the solution here
    trhanx

    Comment

    Working...
    X