1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.components;
22
23 import org.apache.struts2.views.annotations.StrutsTag;
24 import org.apache.struts2.views.annotations.StrutsTagAttribute;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import com.opensymphony.xwork2.util.ValueStack;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31 import java.util.Map;
32 import java.util.LinkedHashMap;
33
34 /***
35 * <!-- START SNIPPET: javadoc -->
36 *
37 * Create a input transfer select component which is basically an text input
38 * and <select ...> tag with buttons in the middle of them allowing text
39 * to be added to the transfer select. Will auto-select all its
40 * elements upon its containing form submision.
41 *
42 * <!-- END SNIPPET: javadoc -->
43 *
44 * <p/>
45 *
46 *
47 * <!-- START SNIPPET: notice -->
48 *
49 * NOTE: The id and doubleId need not be supplied as they will generated provided
50 * that the inputtransferselect tag is being used in a form tag. The generated id
51 * and doubleId will be <form_id>_<inputtransferselect_doubleName> and
52 * <form_id>_<inputtransferselect_doubleName> respectively.
53 *
54 * <!-- END SNIPPET: notice -->
55 *
56 * <p/>
57 *
58 * <pre>
59 * <!-- START SNIPPET: example -->
60 *
61 * <-- minimum configuration -->
62 * <s:inputtransferselect
63 * label="Favourite Cartoons Characters"
64 * name="cartoons"
65 * list="{'Popeye', 'He-Man', 'Spiderman'}"
66 * />
67 *
68 * <!-- END SNIPPET: example -->
69 * </pre>
70 *
71 */
72 @StrutsTag(name="inputtransferselect", tldTagClass="org.apache.struts2.views.jsp.ui.InputTransferSelectTag", description="Renders an input form")
73 public class InputTransferSelect extends ListUIBean {
74
75 private static final Log _log = LogFactory.getLog(InputTransferSelect.class);
76
77 private static final String TEMPLATE = "inputtransferselect";
78
79 protected String size;
80 protected String multiple;
81
82 protected String allowRemoveAll;
83 protected String allowUpDown;
84
85 protected String leftTitle;
86 protected String rightTitle;
87
88 protected String buttonCssClass;
89 protected String buttonCssStyle;
90
91 protected String addLabel;
92 protected String removeLabel;
93 protected String removeAllLabel;
94 protected String upLabel;
95 protected String downLabel;
96
97 protected String headerKey;
98 protected String headerValue;
99
100
101 public InputTransferSelect(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
102 super(stack, request, response);
103 }
104
105 protected String getDefaultTemplate() {
106 return TEMPLATE;
107 }
108
109
110 public void evaluateExtraParams() {
111 super.evaluateExtraParams();
112
113 if (size == null || size.trim().length() <= 0) {
114 addParameter("size", "5");
115 }
116
117 if (multiple == null || multiple.trim().length() <= 0) {
118 addParameter("multiple", Boolean.TRUE);
119 }
120
121
122 addParameter("allowUpDown", allowUpDown != null ? findValue(allowUpDown, Boolean.class) : Boolean.TRUE);
123
124
125 addParameter("allowRemoveAll", allowRemoveAll != null ? findValue(allowRemoveAll, Boolean.class) : Boolean.TRUE);
126
127
128
129 if (leftTitle != null) {
130 addParameter("leftTitle", findValue(leftTitle, String.class));
131 }
132
133
134 if (rightTitle != null) {
135 addParameter("rightTitle", findValue(rightTitle, String.class));
136 }
137
138
139
140 if (buttonCssClass != null && buttonCssClass.trim().length() > 0) {
141 addParameter("buttonCssClass", buttonCssClass);
142 }
143
144
145 if (buttonCssStyle != null && buttonCssStyle.trim().length() > 0) {
146 addParameter("buttonCssStyle", buttonCssStyle);
147 }
148
149
150 addParameter("addLabel", addLabel != null ? findValue(addLabel, String.class) : "->" );
151
152
153 addParameter("removeLabel", removeLabel != null ? findValue(removeLabel, String.class) : "<-");
154
155
156 addParameter("removeAllLabel", removeAllLabel != null ? findValue(removeAllLabel, String.class) : "<<--");
157
158
159
160 addParameter("upLabel", upLabel != null ? findValue(upLabel, String.class) : "^");
161
162
163
164 addParameter("downLabel", downLabel != null ? findValue(downLabel, String.class) : "v");
165
166 if ((headerKey != null) && (headerValue != null)) {
167 addParameter("headerKey", findString(headerKey));
168 addParameter("headerValue", findString(headerValue));
169 }
170
171
172
173
174
175 Form formAncestor = (Form) findAncestor(Form.class);
176 if (formAncestor != null) {
177
178
179 enableAncestorFormCustomOnsubmit();
180
181
182
183 Map formInputtransferselectIds = (Map) formAncestor.getParameters().get("inputtransferselectIds");
184
185
186 if (formInputtransferselectIds == null) {
187 formInputtransferselectIds = new LinkedHashMap();
188 }
189
190
191 String tmpId = (String) getParameters().get("id");
192 String tmpHeaderKey = (String) getParameters().get("headerKey");
193 if (tmpId != null && (! formInputtransferselectIds.containsKey(tmpId))) {
194 formInputtransferselectIds.put(tmpId, tmpHeaderKey);
195 }
196
197 formAncestor.getParameters().put("inputtransferselectIds", formInputtransferselectIds);
198
199 }
200 else {
201 _log.warn("form enclosing inputtransferselect "+this+" not found, auto select upon form submit of inputtransferselect will not work");
202 }
203 }
204
205 public String getSize() {
206 return size;
207 }
208
209 @StrutsTagAttribute(description="the size of the select box")
210 public void setSize(String size) {
211 this.size = size;
212 }
213
214 public String getMultiple() {
215 return multiple;
216 }
217
218 @StrutsTagAttribute(description="Determine whether or not multiple entries are shown")
219 public void setMultiple(String multiple) {
220 this.multiple = multiple;
221 }
222
223 public String getAllowRemoveAll() {
224 return allowRemoveAll;
225 }
226
227 @StrutsTagAttribute(description="Determine whether the remove all button will display")
228 public void setAllowRemoveAll(String allowRemoveAll) {
229 this.allowRemoveAll = allowRemoveAll;
230 }
231
232 public String getAllowUpDown() {
233 return allowUpDown;
234 }
235
236 @StrutsTagAttribute(description="Determine whether items in the list can be reordered")
237 public void setAllowUpDown(String allowUpDown) {
238 this.allowUpDown = allowUpDown;
239 }
240
241 public String getLeftTitle() {
242 return leftTitle;
243 }
244
245 @StrutsTagAttribute(description="the left hand title")
246 public void setLeftTitle(String leftTitle) {
247 this.leftTitle = leftTitle;
248 }
249
250 public String getRightTitle() {
251 return rightTitle;
252 }
253
254 @StrutsTagAttribute(description="the right hand title")
255 public void setRightTitle(String rightTitle) {
256 this.rightTitle = rightTitle;
257 }
258
259 public String getButtonCssClass() {
260 return buttonCssClass;
261 }
262
263 @StrutsTagAttribute(description="the css class used for rendering buttons")
264 public void setButtonCssClass(String buttonCssClass) {
265 this.buttonCssClass = buttonCssClass;
266 }
267
268 public String getButtonCssStyle() {
269 return buttonCssStyle;
270 }
271
272 @StrutsTagAttribute(description="the css style used for rendering buttons")
273 public void setButtonCssStyle(String buttonCssStyle) {
274 this.buttonCssStyle = buttonCssStyle;
275 }
276
277 public String getAddLabel() {
278 return addLabel;
279 }
280
281 @StrutsTagAttribute(description="the label used for the add button")
282 public void setAddLabel(String addLabel) {
283 this.addLabel = addLabel;
284 }
285
286 public String getRemoveLabel() {
287 return removeLabel;
288 }
289
290 @StrutsTagAttribute(description="the label used for the remove button")
291 public void setRemoveLabel(String removeLabel) {
292 this.removeLabel = removeLabel;
293 }
294
295 public String getRemoveAllLabel() {
296 return removeAllLabel;
297 }
298
299 @StrutsTagAttribute(description="the label used for the remove all button")
300 public void setRemoveAllLabel(String removeAllLabel) {
301 this.removeAllLabel = removeAllLabel;
302 }
303
304 public String getUpLabel() {
305 return upLabel;
306 }
307
308 @StrutsTagAttribute(description="the label used for the up button")
309 public void setUpLabel(String upLabel) {
310 this.upLabel = upLabel;
311 }
312
313 public String getDownLabel() {
314 return downLabel;
315 }
316
317 @StrutsTagAttribute(description="the label used for the down button")
318 public void setDownLabel(String downLabel) {
319 this.downLabel = downLabel;
320 }
321
322 public String getHeaderKey() {
323 return headerKey;
324 }
325
326 @StrutsTagAttribute(description="the header key of the select box")
327 public void setHeaderKey(String headerKey) {
328 this.headerKey = headerKey;
329 }
330
331 public String getHeaderValue() {
332 return headerValue;
333 }
334
335 @StrutsTagAttribute(description="the header value of the select box")
336 public void setHeaderValue(String headerValue) {
337 this.headerValue = headerValue;
338 }
339 }