Handling ViewExpiredException depending on the current view

我与影子孤独终老i 提交于 2019-12-21 20:32:56

问题


I am using JSF 2.0 and Primefaces in my project.

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

I am using ViewScoped backing beans.

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.

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.

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

Please help me how to do.


回答1:


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;

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

vee.getViewId();

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

Or, I think you could also do -

FacesContext.getExternalContext().redirect(url);
FacesContext.responseComplete();

to redirect.



来源:https://stackoverflow.com/questions/7573135/handling-viewexpiredexception-depending-on-the-current-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!