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