JSF2 navigation can be done in couple of ways:
1. in the action bean, directly return page filename to "forward"(default) to, or "redirect"(need to define) to:
// a "redirect"(thus a new request sent from client) example.
public String yourActionMethod() {
// do your business
...
// return the page to "redirect" to.
// this might be useful to get new result after done insertion, update etc.
return "nextPage.xhtml?faces-redirect=true";
}
[/code]
2. define the page in UI component, like commandButton, attribute "action":
3. in the "faces-config.xml. this is same to JSF1.2 and disgusting.
1. in the action bean, directly return page filename to "forward"(default) to, or "redirect"(need to define) to:
// a "forward"(default behavior) example.
public String yourActionMethod() {
// do your business
...
// return the page to "forward" to
// 1. also working: "nextPage", "nextPage.jsf"(if mapping to .jsf)
// 2. if not in same folder, relative/full path required: "path_to_page/nextPage.xhtml"
return "nextPage.xhtml"; // this is in same folder
}
// a "redirect"(thus a new request sent from client) example.
public String yourActionMethod() {
// do your business
...
// return the page to "redirect" to.
// this might be useful to get new result after done insertion, update etc.
return "nextPage.xhtml?faces-redirect=true";
}
[/code]
2. define the page in UI component, like commandButton, attribute "action":
<h:commandButton value="Go Search" action="/search/doSearch.xhtml"/>
3. in the "faces-config.xml. this is same to JSF1.2 and disgusting.
<navigation-rule>
<from-view-id>page1.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>page2.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>error</from-outcome>
<to-view-id>/error.xhtml</to-view-id>
</navigation-case>
</navigation-rule>