When I do not use the <redirect/>
tag in faces-config.xml
, it does not update the browser URL, but the data is loaded successfully from the backing bean. When I use <redirect/>
, the browser URL is updated, but the data is not loading from backing bean. How do I load the data from backing bean in this case?

- 1,082,665
- 372
- 3,610
- 3,555

- 21
- 2
-
could you please show the navigation rule. Cheers! – SimonSez Mar 21 '13 at 10:04
3 Answers
You can use faces-redirect=true
in your navigation URL
For example
<h:form>
<h:commandLink value="MyValue" action="MyPage?faces-redirect=true" />
</h:form>
Without define <redirect/>
in your faces-config.xml
Now
- The browser URL will be updated
- The data is loaded successfully from the backing bean.

- 17,392
- 11
- 61
- 88
JSF submits the form to the current page instead of to the target page and therefore the URL shown in your addressbar will always be one request behind.
Example:
Base-URL: example.org/index.jsf // now we navigate to home.jsf
URL: example.org/home.jsf | Addressbar: example.org/index.jsf
// navigate to content.jsf
URL: example.org/content.jsf | Addressbar: example.org/home.jsf
// and so on
By using the the faces-redirect=true
-parameter you're telling the servlet to re-route your request so that the addressbar gets updatet to the actual site you're on.
This behavior is especially wanted if the user should be able to bookmark this site explicitly.
So the first question would be: should this page be bookmarkable?
If so you'll have to use the redirect method either by creating a navigation rule in faces-config.xml
(like you did) or you could use the implicite navigation by telling your action-component (commandLink/Button) the destination-viewId and append ?faces-redirect=true
to it.
If there is no need for bookmarking this page (or any other kind of operation where a GET-request is needed) you could waive to mess around with this and just stick with the standard POST-request.
Cheers
-
The explanation in your 1st paragraph is technically wrong. It's not because JSF is using POST. It's just because JSF submits the form to the current page instead of to the target page. – BalusC Mar 21 '13 at 12:12
Just do the loading job in (post)constructor of the backing bean associated with the target page, if necessary based on some request parameters.
E.g.
@ManagedBean
@RequestScoped
public class Bean {
private Data data;
@PostConstruct
public void init() {
data = loadItSomehow();
}
// ...
}
If the target page references the bean by #{bean}
, then it will be automatically constructed and you can just do all the job in the constructor or @PostConstruct
method or even a listener method attached to <f:event type="preRenderView">
if you happen to have <f:viewParam>
instead of @ManagedProperty
.