use*_*234 3 jsf primefaces jsf-2 viewexpiredexception
我在我的项目中使用JSF 2.0和Primefaces.
我有两个xhtml页面,即Cars.xhtml和Bikes.xhtml.
我正在使用ViewScoped支持bean.
目前如果从两个页面中的任何一个获取视图过期异常,我将在web.xml中处理它.通过error-page标签并指向welcome.xhtml.
现在,如果我从Bikes.xhtml获得一个viewexpired异常,我需要指向另一个页面,即BikesHome.xhtml而不是welcome.xhtml.
如果异常来自Cars.xhtml,则应显示welcome.xhtml.
请帮我怎么做.
我不是100%肯定这个(因为我自己没有尝试过)但是这里是我的建议 - 检查这个在JSF2中使用ViewExpiredException进行优雅处理.
if (t instanceof ViewExpiredException) {
ViewExpiredException vee = (ViewExpiredException) t;
Run Code Online (Sandbox Code Playgroud)
此时你可以得到view id如下 -
vee.getViewId();
Run Code Online (Sandbox Code Playgroud)
然后根据view id所需的导航.
NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
//check condition, set view
nv.handleNavigation(facesContext, null, "/view-id?faces-redirect=true");
facesContext.renderResponse();
Run Code Online (Sandbox Code Playgroud)
或者,我认为你也可以这样做 -
FacesContext.getExternalContext().redirect(url);
FacesContext.responseComplete();
Run Code Online (Sandbox Code Playgroud)
重定向.