Navigated Programatically in JSF

I would like to be able to navigate programatically using JSF. I.e., to forward or sendRedirect() in an action listener method.

In such a method, I was able to get the response:

FacesContext aJSFContext = FacesContext.getCurrentInstance();

ExternalContext aContext = aJSFContext.getExternalContext();

HttpServletResponse aResp =

(HttpServletResponse)aContext.getResponse();

aResp.sendRedirect("myurl");

Here, I get an invalid state exception.

So, can I control when any part of the reponse gets sent out, or is there another way to do this without having to put everything in the navigation rules in faces-config.xml?

Thanks,

Charlie

[725 byte] By [cfinka] at [2007-10-2 16:40:37]
# 1
try thisFacesContext.getCurrentInstance().getExternalContext().redirect(((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getContextPath() + "/faces/page.jspx");
pringia at 2007-7-13 17:49:12 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...