1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.dojo.components;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.struts2.components.Form;
28 import org.apache.struts2.views.annotations.StrutsTagAttribute;
29
30 import com.opensymphony.xwork2.util.ValueStack;
31
32 /***
33 * Base class for tags that perform AJAX validation
34 */
35 public abstract class AbstractValidateBean extends AbstractRemoteBean {
36 protected String validate;
37 protected String ajaxAfterValidation;
38
39 public AbstractValidateBean(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
40 super(stack, request, response);
41 }
42
43 public void evaluateExtraParams() {
44 super.evaluateExtraParams();
45
46 if (validate != null)
47 addParameter("validate", findValue(validate, Boolean.class));
48 if (ajaxAfterValidation != null)
49 addParameter("ajaxAfterValidation", findValue(ajaxAfterValidation, Boolean.class));
50
51 Form form = (Form) findAncestor(Form.class);
52 if (form != null)
53 addParameter("parentTheme", form.getTheme());
54 }
55
56 @StrutsTagAttribute(description = "Perform Ajax validation. 'ajaxValidation' interceptor must be applied to action", type="Boolean",
57 defaultValue = "false")
58 public void setValidate(String validate) {
59 this.validate = validate;
60 }
61
62 @StrutsTagAttribute(description = "Make an asynchronous request if validation succeeds. Only valid if 'validate' is 'true'", type="Boolean",
63 defaultValue = "false")
64 public void setAjaxAfterValidation(String ajaxAfterValidation) {
65 this.ajaxAfterValidation = ajaxAfterValidation;
66 }
67 }