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.taglib.html;
22
23 import org.apache.struts.taglib.TagUtils;
24 import org.apache.struts.util.MessageResources;
25
26 import javax.servlet.jsp.JspException;
27
28
29
30
31
32
33
34 public class SubmitTag extends BaseHandlerTag {
35
36
37
38
39
40 protected static MessageResources messages =
41 MessageResources.getMessageResources(Constants.Package
42 + ".LocalStrings");
43
44
45
46
47 protected String property = null;
48
49
50
51
52 protected String text = null;
53
54
55
56
57 protected String value = null;
58
59
60
61
62
63
64 public String getProperty() {
65 return (this.property);
66 }
67
68
69
70
71
72
73 public void setProperty(String property) {
74 this.property = property;
75 }
76
77
78
79
80 public String getValue() {
81 return (this.value);
82 }
83
84
85
86
87
88
89 public void setValue(String value) {
90 this.value = value;
91 }
92
93
94
95
96
97
98
99
100 public int doStartTag() throws JspException {
101
102 this.text = null;
103
104 return (EVAL_BODY_TAG);
105 }
106
107
108
109
110
111
112 public int doAfterBody() throws JspException {
113 if (bodyContent != null) {
114 String value = bodyContent.getString().trim();
115
116 if (value.length() > 0) {
117 text = value;
118 }
119 }
120
121 return (SKIP_BODY);
122 }
123
124
125
126
127
128
129
130 public int doEndTag() throws JspException {
131
132 StringBuffer results = new StringBuffer();
133
134 results.append(getElementOpen());
135 prepareAttribute(results, "name", prepareName());
136 prepareButtonAttributes(results);
137 results.append(prepareEventHandlers());
138 results.append(prepareStyles());
139 prepareOtherAttributes(results);
140 results.append(getElementClose());
141
142 TagUtils.getInstance().write(pageContext, results.toString());
143
144 return (EVAL_PAGE);
145 }
146
147
148
149
150
151
152 protected String getElementOpen() {
153 return "<input type=\"submit\"";
154 }
155
156
157
158
159
160
161 protected String prepareName()
162 throws JspException {
163 if (property == null) {
164 return null;
165 }
166
167
168 if (indexed) {
169 StringBuffer results = new StringBuffer();
170
171 results.append(property);
172 prepareIndex(results, null);
173
174 return results.toString();
175 }
176
177 return property;
178 }
179
180
181
182
183
184
185 protected void prepareButtonAttributes(StringBuffer results)
186 throws JspException {
187 prepareAttribute(results, "accesskey", getAccesskey());
188 prepareAttribute(results, "tabindex", getTabindex());
189 prepareValue(results);
190 }
191
192
193
194
195
196
197 protected void prepareValue(StringBuffer results) {
198
199 String label = value;
200
201 if ((label == null) && (text != null)) {
202 label = text;
203 }
204
205 if ((label == null) || (label.length() < 1)) {
206 label = getDefaultValue();
207 }
208
209 prepareAttribute(results, "value", label);
210 }
211
212
213
214
215
216
217 protected String getDefaultValue() {
218 return "Submit";
219 }
220
221
222
223
224 public void release() {
225 super.release();
226 property = null;
227 text = null;
228 value = null;
229 }
230 }