I want to be able to do semething in the likes of:
@ManagedBean
class MyBackingBean {
public void processRequest() {
String viewName;
if (condition1)
viewName = "page1";
else if (condition2)
viewName = "pagexx";
invokeAndRenderXHTML(viewName);
}
}
thanks
Just in case anyone stumbles upon this old question: you can programatically invoke navigation handler like this
FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(), null, "YOUR_NAVIGATION_CASE_DEFINED_IN_FACES_CONFIG");
JSF provides programmatic navigation by default. You do NOT need a third party library to effect navigation. To use JSF navigation, your method should simply return the name of the view you're trying to access and it'll navigate to that page. You could also include an optional redirect parameter to the return value to instruct the JSF context to redirect the response in full to the destination view. For your needs, just change processRequest to
public String processRequest() {
// String viewName unnecessary
if (condition1) {
return "page1";
}
else if (condition2) {
return = "pagexx";
}
return null;
// invokeAndRenderXHTML(viewName) becomes unnecessary
}
If you choose to have the redirect option like I indicated above just change the return String to
return "page1?faces-redirect=true"
the faces-redirect=true is the parameter that does the redirect magic
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With