GateIn - redirect within portlet

459 views Asked by At

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.

2

There are 2 answers

0
rbiggy On BEST ANSWER

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().

1
Romain Dénarié On

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.