如何重定向到" ErrorPage"如果在" beforePhase"?中发生异常。当我试图重新指示它给我一个"响应已经承诺"。
此致 拉吉
答案 0 :(得分:0)
检查以下代码是否对您有帮助,
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();
}
}