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 TEMPLATE = "submit";
58 protected String src;
59
60 public Submit(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
61 super(stack, request, response);
62 }
63
64 protected String getDefaultTemplate() {
65 return TEMPLATE;
66 }
67
68 public void evaluateParams() {
69 if ((key == null) && (value == null)) {
70 value = "Submit";
71 }
72
73 if (((key != null)) && (value == null)) {
74 this.value = "%{getText('"+key +"')}";
75 }
76
77 super.evaluateParams();
78 }
79
80 public void evaluateExtraParams() {
81 super.evaluateExtraParams();
82
83 if (src != null)
84 addParameter("src", findString(src));
85 }
86
87 /***
88 * Indicate whether the concrete button supports the type "image".
89 *
90 * @return <tt>true</tt> to indicate type image is supported.
91 */
92 protected boolean supportsImageType() {
93 return true;
94 }
95
96 @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>.")
97 public void setSrc(String src) {
98 this.src = src;
99 }
100
101 /***
102 * Overrides to be able to render body in a template rather than always before the template
103 */
104 public boolean end(Writer writer, String body) {
105 evaluateParams();
106 try {
107 addParameter("body", body);
108
109 mergeTemplate(writer, buildTemplateName(template, getDefaultTemplate()));
110 } catch (Exception e) {
111 LOG.error("error when rendering", e);
112 }
113 finally {
114 popComponentStack();
115 }
116
117 return false;
118 }
119 }