View Javadoc

1   /*
2    * $Id: UpdateModelValuesInterceptor.java 440597 2006-09-06 03:34:39Z wsmoak $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.jsf;
19  
20  import javax.faces.FacesException;
21  import javax.faces.context.FacesContext;
22  import javax.faces.event.PhaseId;
23  
24  /***
25   * Updates the model values from the component tree
26   */
27  public class UpdateModelValuesInterceptor extends FacesInterceptor {
28  
29      private static final long serialVersionUID = 4011504235094251077L;
30  
31      /***
32       * Update Model Values (JSF.2.2.4)
33       * 
34       * @param viewId
35       *            The view id
36       * @param facesContext
37       *            The faces context
38       * @return true, if response is complete
39       */
40      protected boolean executePhase(String viewId, FacesContext facesContext)
41              throws FacesException {
42          boolean skipFurtherProcessing = false;
43          if (log.isTraceEnabled())
44              log.trace("entering updateModelValues");
45  
46          informPhaseListenersBefore(facesContext, PhaseId.UPDATE_MODEL_VALUES);
47  
48          try {
49              if (isResponseComplete(facesContext, "updateModelValues", true)) {
50                  // have to return right away
51                  return true;
52              }
53              if (shouldRenderResponse(facesContext, "updateModelValues", true)) {
54                  skipFurtherProcessing = true;
55              }
56  
57              facesContext.getViewRoot().processUpdates(facesContext);
58          } finally {
59              informPhaseListenersAfter(facesContext, PhaseId.UPDATE_MODEL_VALUES);
60          }
61  
62          if (isResponseComplete(facesContext, "updateModelValues", false)
63                  || shouldRenderResponse(facesContext, "updateModelValues",
64                          false)) {
65              // since this phase is completed we don't need to return right away
66              // even if the response is completed
67              skipFurtherProcessing = true;
68          }
69  
70          if (!skipFurtherProcessing && log.isTraceEnabled())
71              log.trace("exiting updateModelValues");
72  
73          return skipFurtherProcessing;
74      }
75  }