KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > chain > servlet > ValidateActionForm


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.struts.chain.servlet;
18
19
20 import org.apache.commons.chain.Context;
21 import org.apache.commons.chain.web.servlet.ServletWebContext;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.struts.action.ActionErrors;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.chain.AbstractValidateActionForm;
28 import org.apache.struts.config.ActionConfig;
29 import org.apache.struts.Globals;
30
31
32 /**
33  * <p>Validate the properties of the form bean for this request. If there are
34  * any validation errors, execute the child commands in our chain; otherwise,
35  * proceed normally. Also, if any errors are found and the request is a
36  * multipart request, rollback the <code>MultipartRequestHandler</code>.</p>
37  *
38  * @author Craig R. McClanahan
39  * @author Don Brown
40  * @version $Rev: 54933 $ $Date: 2004-10-16 18:04:52 +0100 (Sat, 16 Oct 2004) $
41  */

42
43 public class ValidateActionForm extends AbstractValidateActionForm {
44
45     // ------------------------------------------------------ Instance Variables
46

47
48     private static final Log log =
49         LogFactory.getLog(ValidateActionForm.class);
50
51
52     // ------------------------------------------------------- Protected Methods
53

54
55     /**
56      * <p>Call the <code>validate()</code> method of the specified form bean,
57      * and return the resulting <code>ActionErrors</code> object.</p>
58      *
59      * @param context The context for this request
60      * @param actionForm The form bean for this request
61      */

62     protected ActionErrors validate(Context context,
63                                     ActionConfig actionConfig,
64                                     ActionForm actionForm) {
65
66         ServletWebContext swcontext = (ServletWebContext) context;
67         ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig,
68                                     swcontext.getRequest()));
69
70         // Special handling for multipart request
71
if (errors != null && !errors.isEmpty()) {
72             if (actionForm.getMultipartRequestHandler() != null) {
73                 if (log.isTraceEnabled()) {
74                     log.trace(" Rolling back multipart request");
75                 }
76                 actionForm.getMultipartRequestHandler().rollback();
77             }
78         }
79
80         // Saving the errors is not part of the contract for this method,
81
// but the idea of the HttpServletRequest is not present in the
82
// abstract parent of this class. Put this in now so that it
83
// at least gets done -- and then see if other developers have
84
// opinions about whether this is good, bad, or at least acceptable.
85
swcontext.getRequest().setAttribute(Globals.ERROR_KEY, errors);
86
87         return errors;
88
89     }
90
91
92 }
93
Popular Tags