如何避免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>

你可能感兴趣的:(object,JSF,null,PostBack)