Reputation:
I have following code for initializing bean values depending upon url parameter.
<f:metadata>
<f:viewParam name="id" value="#{inningBean.inningId}" />
<f:event type="preRenderView"
listener="#{inningBean.initInningBeanForBallByBallScoring}" />
</f:metadata>
This is working fine. But I want that in certain conditions(some validation forexample), the user is redirected to another page from listener method.
How can I do that?
Upvotes: 4
Views: 4443
Reputation: 1108722
Use ExternalContext#redirect()
.
public void initInningBeanForBallByBallScoring() throws IOException {
// ...
if (someCondition) {
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/other.xhtml");
}
}
Upvotes: 4