根据当前视图处理ViewExpiredException [英] Handling ViewExpiredException depending on the current view

查看:83
本文介绍了根据当前视图处理ViewExpiredException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用JSF 2.0和Primefaces.

I am using JSF 2.0 and Primefaces in my project.

我有两个xhtml页面,即Cars.xhtml和Bikes.xhtml.

I have two xhtml pages namely Cars.xhtml and Bikes.xhtml.

我正在使用ViewScoped支持bean.

I am using ViewScoped backing beans.

当前,如果两个页面中任何一个页面的获取视图过期异常,请在web.xml中对其进行处理. 通过错误页面标签并定向到welcome.xhtml.

Currently If get view expired exception from any of the two pages,im handling it in the web.xml. through the error-page tag and directing to welcome.xhtml.

现在,如果我从Bikes.xhtml获得viewexpired异常 我需要直接转到另一个页面,即BikesHome.xhtml而不是welcome.xhtml.

Now If i get a viewexpired exception from Bikes.xhtml I need to direct to another page which is BikesHome.xhtml instead of welcome.xhtml.

如果异常来自Cars.xhtml,则应显示welcome.xhtml.

If the exception is from Cars.xhtml, welcome.xhtml should be shown.

请帮我怎么做.

推荐答案

对此我不是100%肯定(因为我自己还没有尝试过),但这是我的建议- 在在JSF2中使用ViewExpiredException进行优雅处理.

I not 100% sure about this (because I haven't tried it myself) but here is my suggestion for - Check this out Dealing Gracefully with ViewExpiredException in JSF2.

if (t instanceof ViewExpiredException) {
    ViewExpiredException vee = (ViewExpiredException) t;

此时,您可以按以下方式获得view id-

At this point you can get the view id as follows -

vee.getViewId();

,然后基于view id进行所需的导航.

And then based on the view id do the desired navigation.

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();

重定向.

这篇关于根据当前视图处理ViewExpiredException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆