如果“beforePhase”发生异常,如何重定向到“ErrorPage”?当我尝试重新定向时,它给了我一个“已经提交的响应”。
问候拉吉
检查以下代码是否对您有帮助,
public void beforePhase(PhaseEvent e)
{
try
{
//if something doesn't work here
}
catch(Exception e)
{
System.out.println("Exception ocurred in beforePhase method");
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext externalContext = context.getExternalContext();
UIViewRoot newPage = context.getApplication().getViewHandler().createView(context,"/pages/techErrorPage.jsf");
context.setViewRoot(newPage);
context.renderResponse();
}
}