1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.chain.commands.servlet;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.struts.action.ActionErrors;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.chain.commands.AbstractValidateActionForm;
29 import org.apache.struts.chain.contexts.ActionContext;
30 import org.apache.struts.chain.contexts.ServletActionContext;
31 import org.apache.struts.config.ActionConfig;
32
33 /**
34 * <p>Validate the properties of the form bean for this request. If there are
35 * any validation errors, execute the child commands in our chain; otherwise,
36 * proceed normally. Also, if any errors are found and the request is a
37 * multipart request, rollback the <code>MultipartRequestHandler</code>.</p>
38 *
39 * @version $Rev: 471754 $ $Date: 2005-06-04 10:58:46 -0400 (Sat, 04 Jun 2005)
40 * $
41 */
42 public class ValidateActionForm extends AbstractValidateActionForm {
43
44 private static final Log log = LogFactory.getLog(ValidateActionForm.class);
45
46
47
48 /**
49 * <p>Call the <code>validate()</code> method of the specified form bean,
50 * and return the resulting <code>ActionErrors</code> object.</p>
51 *
52 * @param context The context for this request
53 * @param actionForm The form bean for this request
54 */
55 protected ActionErrors validate(ActionContext context,
56 ActionConfig actionConfig, ActionForm actionForm) {
57 ServletActionContext saContext = (ServletActionContext) context;
58 ActionErrors errors =
59 (actionForm.validate((ActionMapping) actionConfig,
60 saContext.getRequest()));
61
62
63 if ((errors != null) && !errors.isEmpty()) {
64 if (actionForm.getMultipartRequestHandler() != null) {
65 if (log.isTraceEnabled()) {
66 log.trace(" Rolling back multipart request");
67 }
68
69 actionForm.getMultipartRequestHandler().rollback();
70 }
71 }
72
73 return errors;
74 }
75 }