Question

How can you redirect a user by URL (within backing bean) to some other page within portlet? We are using GateIn 3.1 on JBoss 5.1.0

Usually, FacesContext.getCurrentInstance().getExternalContext().redirect("url") is enough, but here it doesn't work, it doesn't redirect user.

context.getApplication().getNavigationHandler().handleNavigation(context, null, page) doesn't work either.

We want to avoid making navigation rules for every possible page we can redirect to.

EDIT: It appears a4j:commandButton was causing some problems, after we replaced it with h:commandButton we are being redirected but not only within portlet but within portal.

Was it helpful?

Solution 2

The only other alternative (to having many navigation cases in faces-config.xml) I've found that works is using FacesContext.getCurrentInstance().getViewRoot().setViewId(page) to redirect, where page is String page = FacesContext.getCurrentInstance().getViewRoot().getViewId().

OTHER TIPS

To have sendRedirect available, you have to cast object response to HttpServletResponse :

HttpServletResponse objHttpServletResponse = (HttpServletResponse)
                          FacesContext.getCurrentInstance()
                                      .getExternalContext()
                                      .getResponse();
objHttpServletResponse.sendRedirect(url);

This is doing a 302 redirect, managed by browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top