我在我的项目中使用JSF 2.0和Primefaces。
我有两个xhtml页面,即Cars.xhtml和Bikes.xhtml。
我使用的是ViewScoped backing。
目前,如果从这两个页面中的任何一个获取视图过期异常,我会在web.xml中处理它。通过error-page标记并定向到welcome.xhtml。
现在,如果我从Bikes.xhtml得到一个视图过期异常,我需要指向另一个页面,这个页面是BikesHome.xhtml而不是welcome.xhtml。
如果异常来自Cars.xhtml,则应显示welcome.xhtml。
请帮帮我怎么做。
发布于 2011-09-28 02:19:01
我对此不是百分之百确定(因为我自己还没有尝试过),但这里是我的建议--看看这个Dealing Gracefully with ViewExpiredException in JSF2。
if (t instanceof ViewExpiredException) {
ViewExpiredException vee = (ViewExpiredException) t;此时,您可以获得view id,如下所示-
vee.getViewId();然后基于view id进行所需的导航。
NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
//check condition, set view
nv.handleNavigation(facesContext, null, "/view-id?faces-redirect=true");
facesContext.renderResponse();或者,我想你也可以-
FacesContext.getExternalContext().redirect(url);
FacesContext.responseComplete();重定向。
https://stackoverflow.com/questions/7573135
复制相似问题