View Javadoc

1   /*
2    * $Id: ProcessValidationsInterceptor.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   * Processes validations on the component tree
26   */
27  public class ProcessValidationsInterceptor extends FacesInterceptor {
28  
29  	private static final long serialVersionUID = 8785236570688278147L;
30  
31  	/***
32  	 * Process Validations (JSF.2.2.3)
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 processValidations");
45  
46  		informPhaseListenersBefore(facesContext, PhaseId.PROCESS_VALIDATIONS);
47  
48          try {
49          		if (isResponseComplete(facesContext, "processValidations", true)) {
50          			// have to return right away
51          			return true;
52          		}
53          		if (shouldRenderResponse(facesContext, "processValidations", true)) {
54          			skipFurtherProcessing = true;
55          		}
56          
57          		facesContext.getViewRoot().processValidators(facesContext);
58          } finally {
59              informPhaseListenersAfter(facesContext, PhaseId.PROCESS_VALIDATIONS);
60          }
61  
62  		if (isResponseComplete(facesContext, "processValidations", false)
63  				|| shouldRenderResponse(facesContext, "processValidations",
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 processValidations");
72  		return skipFurtherProcessing;
73  	}
74  }