Handling the navigation from a backing bean
Yesterday I was experiencing some login form, in which I am calling a backing bean when the login button is pressed. In the backing bean depending on the return of the operation call I want to redirect the navigation to the corresponding page. After doing some research in the forums I found the below solution. We use NavigationHandler class to redirect the flow of the application.
public String doLogin() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("login");
Object result = operationBinding.execute();
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler nh = context.getApplication().getNavigationHandler();
if (((String)result).equals("SUCCESS"))
nh.handleNavigation(context, null, "SUCCESS");
else
nh.handleNavigation(context, null, "ERROR");
return null;
}
public String doLogin() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("login");
Object result = operationBinding.execute();
FacesContext context = FacesContext.getCurrentInstance();
NavigationHandler nh = context.getApplication().getNavigationHandler();
if (((String)result).equals("SUCCESS"))
nh.handleNavigation(context, null, "SUCCESS");
else
nh.handleNavigation(context, null, "ERROR");
return null;
}
Comments