1 Reply Latest reply on Dec 15, 2006 10:13 AM by pbrewer_uk

    Redirecting into view that is inside a directory

    thejavafreak

      Dear all,

      I have a problem where I haven't been able to figure out how to redirect a view that is inside a directory

      This is how /index.jsp looks like:

      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
      <c:redirect url="home.seam" />


      And this is my navigation rule:
      <navigation-rule>
       <navigation-case>
       <from-outcome>home</from-outcome>
       <to-view-id>/department/home.xhtml</to-view-id>
       <redirect />
       </navigation-case>
       </navigation-rule>


      From the webcontext root directory, the view is located under /department directory. I expect to get the view /department/home.xhtml displayed, but it didn't work. Have I missed on something here?

      Thanks in advance

        • 1. Re: Redirecting into view that is inside a directory
          pbrewer_uk

          If I understand correctly, then I should explain how navigation rules are supposed to work. This is how your current setup will work: Your /index.jsp will redirect to /home.seam which, in turn will map to a file in your war called /home.xhtml which will then be rendered on the front-end. (Note no navigation rule is involved here.)

          The navigation rules are supposed to be used as action outcomes: looking at the seam booking example, there is a login action method that returns an outcome of either "login" or "main" these outcomes are then mapped, in the faces-config.xml file (see below), to views.

          Seam also introduces the concept of stateful navigation through the use of Pageflows. Have a look at the seam reference for more info on this.

          LoginAction.java extract...

           public String login()
           {
           List<User> results = em.createQuery("select u from User u where u.username=:username and u.password=:password")
           .setParameter("username", user.getUsername())
           .setParameter("password", user.getPassword())
           .getResultList();
          
           if ( results.size()==0 )
           {
           FacesMessages.instance().add("Invalid login");
           return "login";
           }
           else
           {
           user = results.get(0);
           Contexts.getSessionContext().set("loggedIn", true);
           FacesMessages.instance().add("Welcome, #{user.name}");
           return "main";
           }
          
           }
          


          faces-config.xml extract...
           <navigation-rule>
          
           <navigation-case>
           <from-outcome>login</from-outcome>
           <to-view-id>/home.xhtml</to-view-id>
           <redirect />
           </navigation-case>
          
           <navigation-case>
           <from-outcome>register</from-outcome>
           <to-view-id>/register.xhtml</to-view-id>
           <redirect />
           </navigation-case>
          
           <navigation-case>
           <from-outcome>password</from-outcome>
           <to-view-id>/password.xhtml</to-view-id>
           <redirect />
           </navigation-case>
          
           <navigation-case>
           <from-outcome>main</from-outcome>
           <to-view-id>/main.xhtml</to-view-id>
           <redirect />
           </navigation-case>
          
           <navigation-case>
           <from-outcome>hotel</from-outcome>
           <to-view-id>/hotel.xhtml</to-view-id>
           <redirect />
           </navigation-case>
          
           </navigation-rule>