1 Reply Latest reply on Feb 11, 2011 2:49 AM by Ilya Sorokoumov

    How to do breadcrumbs using richfaces JSF and spring?

    mckiran87 Newbie

      I tried to do implement breadcrumb application by saving the path in the bean but the problem is i am not able to bring it up that on the webpage

      the layout which needs to be inserted all the pages:

      <rich:spacer height = "30px"/>

      <div>

          <a4j:form id="breadCrumb">

              <a4j:keepAlive beanName="breadCrumbBean" />

              Bread Crumbs:

              <rich:panel>

                  <ui:repeat var="link" value="#{breadCrumbBean.path}">   path is the list of strings which stores the address

                      <h:outputText value ="#{link}"/>

                  </ui:repeat>       

              </rich:panel>

          </a4j:form>

       

      </div>

      </body>

       

      i have used the bean as phase listener also declare this class i faces-config life cycle and also in the spring xml files

       

      public class BreadcrumbBean implements PhaseListener

      {

         private static final long serialVersionUID = 1L;

          private ArrayList<String> path = new ArrayList<String>();

          private String currentPage = "";

          private String newPage = "";

          private String requestedPage ="";

          private PhaseEvent event;

          private String link;

          private String home ="/faces/Home.faces";

       

          public BreadcrumbBean()

          {

              super();

              path.clear();

          }

          @Override

          public void afterPhase(PhaseEvent e) {

              if (e.getPhaseId() == PhaseId.RESTORE_VIEW) {

                  FacesContext context = e.getFacesContext();

                  HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

       

                   setLink(request.getServletPath());

       

                  // System.out.println(link);

                   System.out.println("after  phase");

                   displayPath();

                }

          }

       

       

          private void displayPath()

          {

       

               newPage=link;

               if(!path.contains(link))

               path.add(newPage);

               for (String paths:path)

               System.out.println("displaypath" + paths);

          }

       

          public void linkToThisPage() throws ServiceException

          {       

              String link = FacesContext.getCurrentInstance().getExternalContext()

              .getRequestParameterMap().get("pageLink");

       

              for(String page : path)

              {

                  if(page==link)

                  {

                      PhaseEvent event = getEvent();

                      redirect(link,event.getFacesContext());

                  }

       

              }

           }

      //other functonality is igored for now

          private void redirect(String navigation, FacesContext context){

              context.getApplication().getNavigationHandler().handleNavigation(context, null, navigation);

          }

       

          @Override

          public void beforePhase(PhaseEvent event)

          {

              System.out.println("before phase");

              //if(event.getFacesContext().)                   

          }

       

          private void resetBreadCrumb()

          {

              path.clear();

              path.add(currentPage);

            }

       

          @Override

          public PhaseId getPhaseId()

          {

              return PhaseId.RESTORE_VIEW;

          }

       

      .....getters and setters

       

      it is not working i think the bean is getting populated