如何避免jsf ViewExpiredException

我看了一下RestoreViewPhase.java,在处理View的过程中有这样的代码:

  196           if (isPostBack) {
  197               facesContext.setProcessingEvents(false);
  198               // try to restore the view
  199               viewRoot = viewHandler.restoreView(facesContext, viewId);
  200               if (viewRoot == null) {
  201                   if (is11CompatEnabled(facesContext)) {
  202                       // 1.1 -> create a new view and flag that the response should
  203                       //        be immediately rendered
  204                       if (LOGGER.isLoggable(Level.FINE)) {
  205                           LOGGER.fine("Postback: recreating a view for " + viewId);
  206                       }
  207                       viewRoot = viewHandler.createView(facesContext, viewId);
  208                       facesContext.renderResponse();
  209  
  210                   } else {
  211                       Object[] params = {viewId};
  212                       throw new ViewExpiredException(
  213                             MessageUtils.getExceptionMessageString(
  214                                   MessageUtils.RESTORE_VIEW_ERROR_MESSAGE_ID,
  215                                   params),
  216                             viewId);
  217                   }
  218               }
  219  
  220               facesContext.setViewRoot(viewRoot);
  221               facesContext.setProcessingEvents(true);
  222               if (LOGGER.isLoggable(Level.FINE)) {
  223                   LOGGER.fine("Postback: restored view for " + viewId);
  224               }
  225           }

 

其中is11CompatEnabled如下:

  307       private boolean is11CompatEnabled(FacesContext context) {
  308  
  309           return (getWebConfig(context).isOptionEnabled(
  310                 BooleanWebContextInitParameter.EnableRestoreView11Compatibility));
  311          
  312       } 

 

如果要避免出现ViewExpiredException,可以在web.xml中设置如下:

<context-param>
  <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
  <param-value>true</param-value>
 </context-param>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值