-
1. Re: Redirecting into view that is inside a directory
pbrewer_uk Dec 15, 2006 10:13 AM (in response to thejavafreak)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>