3 Replies Latest reply on Jul 13, 2007 8:11 AM by susnet

    Dynamic navigation

    susnet

      I have an action method which gets which view i want to redirect to. I return this as a String.
      Then i get a browser redirect. I read in the manual: Note that when you use a view id as an outcome, Seam always performs a browser redirect. so this is the way it should be.

      My question is: How do i do if I don't want a browser redirect? I just want to render the view without the URL in the browser changing?

      I cannot use the navigation rules in pages.xml because the view-id is dynamic, I recieve it from my action method (getting it from the database).

      How do I dynamically, programatically render my dynamic view in my Action Method?

        • 1. Re: Dynamic navigation
          susnet

          I almost succeeded in solving this problem with this code:

          @In
          private FacesContext facesContext;
          
          public void navigate () {
          
           String page = "/pages/articles/xyz.xhtml"; // This could be any page, collected from database
          
           UIViewRoot root = facesContext.getApplication ().getViewHandler ().createView (facesContext, page);
           try {
           facesContext.getApplication ().getViewHandler ().renderView (facesContext, root);
           } catch (IOException ioe) {
           log.error (ioe);
           }
           }
          


          But I also get an IllegalStateException, so I guess this is not the right way of doing this.

          ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
          java.lang.IllegalStateException
           at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:404)




          I have also tried this code:

          @In
          private Renderer renderer;
          
          public void navigate () {
           String page = "/pages/articles/xyz.xhtml";
           renderer.render (page);
          }
          

          but it just gives me NPE.


          Any help would really be appreciated!

          • 2. Re: Dynamic navigation
            matt.drees

            You might look at the code in RenderNavigationHandler and NavigationHandler; it might give you some ideas.

            • 3. Re: Dynamic navigation
              susnet

              Thank you very much! This code solved the problem:

              String page = "/pages/articles/xyz.xhtml";
              
              RenderNavigationHandler navHandler = new RenderNavigationHandler(page, null, null);
              navHandler.navigate (FacesContext.getCurrentInstance ());