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.components;
23
24 import java.io.Writer;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28
29 import org.apache.struts2.views.annotations.StrutsTag;
30 import org.apache.struts2.views.annotations.StrutsTagAttribute;
31
32 import com.opensymphony.xwork2.util.ValueStack;
33 import com.opensymphony.xwork2.util.logging.Logger;
34 import com.opensymphony.xwork2.util.logging.LoggerFactory;
35
36 /***
37 * <!-- START SNIPPET: javadoc -->
38 * Render a submit button. The submit tag is used together with the form tag to provide asynchronous form submissions.
39 * The submit can have three different types of rendering:
40 * <ul>
41 * <li>input: renders as html <input type="submit"...></li>
42 * <li>image: renders as html <input type="image"...></li>
43 * <li>button: renders as html <button type="submit"...></li>
44 * </ul>
45 * Please note that the button type has advantages by adding the possibility to seperate the submitted value from the
46 * text shown on the button face, but has issues with Microsoft Internet Explorer at least up to 6.0
47 * <!-- END SNIPPET: javadoc -->
48 */
49 @StrutsTag(
50 name="submit",
51 tldTagClass="org.apache.struts2.views.jsp.ui.SubmitTag",
52 description="Render a submit button",
53 allowDynamicAttributes=true)
54 public class Submit extends FormButton {
55
56 private static final Logger LOG = LoggerFactory.getLogger(Submit.class);
57 final public static String OPEN_TEMPLATE = "submit";
58 final public static String TEMPLATE = "submit-close";
59 protected String src;
60
61 public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
62 super(stack, request, response);
63 }
64
65 public String getDefaultOpenTemplate() {
66 return OPEN_TEMPLATE;
67 }
68
69 protected String getDefaultTemplate() {
70 return TEMPLATE;
71 }
72
73 public void evaluateParams() {
74 if ((key == null) && (value == null)) {
75 value = "Submit";
76 }
77
78 if (((key != null)) && (value == null)) {
79 this.value = "%{getText('"+key +"')}";
80 }
81
82 super.evaluateParams();
83 }
84
85 public void evaluateExtraParams() {
86 super.evaluateExtraParams();
87
88 if (src != null)
89 addParameter("src", findString(src));
90 }
91
92 /***
93 * Indicate whether the concrete button supports the type "image".
94 *
95 * @return <tt>true</tt> to indicate type image is supported.
96 */
97 protected boolean supportsImageType() {
98 return true;
99 }
100
101 @StrutsTagAttribute(description="Supply an image src for <i>image</i> type submit button. Will have no effect for types <i>input</i> and <i>button</i>.")
102 public void setSrc(String src) {
103 this.src = src;
104 }
105
106
107 @Override
108 public boolean usesBody() {
109 return true;
110 }
111
112 /***
113 * Overrides to be able to render body in a template rather than always before the template
114 */
115 public boolean end(Writer writer, String body) {
116 evaluateParams();
117 try {
118 addParameter("body", body);
119
120 mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
121 } catch (Exception e) {
122 LOG.error("error when rendering", e);
123 }
124 finally {
125 popComponentStack();
126 }
127
128 return false;
129 }
130 }