001: /*
002: * $Id: InputTransferSelect.java 502294 2007-02-01 17:28:00Z niallp $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.components;
022:
023: import org.apache.struts2.views.annotations.StrutsTag;
024: import org.apache.struts2.views.annotations.StrutsTagAttribute;
025: import org.apache.commons.logging.Log;
026: import org.apache.commons.logging.LogFactory;
027: import com.opensymphony.xwork2.util.ValueStack;
028:
029: import javax.servlet.http.HttpServletRequest;
030: import javax.servlet.http.HttpServletResponse;
031: import java.util.Map;
032: import java.util.LinkedHashMap;
033:
034: /**
035: * <!-- START SNIPPET: javadoc -->
036: *
037: * Create a input transfer select component which is basically an text input
038: * and <select ...> tag with buttons in the middle of them allowing text
039: * to be added to the transfer select. Will auto-select all its
040: * elements upon its containing form submision.
041: *
042: * <!-- END SNIPPET: javadoc -->
043: *
044: * <p/>
045: *
046: *
047: * <!-- START SNIPPET: notice -->
048: *
049: * NOTE: The id and doubleId need not be supplied as they will generated provided
050: * that the inputtransferselect tag is being used in a form tag. The generated id
051: * and doubleId will be <form_id>_<inputtransferselect_doubleName> and
052: * <form_id>_<inputtransferselect_doubleName> respectively.
053: *
054: * <!-- END SNIPPET: notice -->
055: *
056: * <p/>
057: *
058: * <pre>
059: * <!-- START SNIPPET: example -->
060: *
061: * <-- minimum configuration -->
062: * <s:inputtransferselect
063: * label="Favourite Cartoons Characters"
064: * name="cartoons"
065: * list="{'Popeye', 'He-Man', 'Spiderman'}"
066: * />
067: *
068: * <!-- END SNIPPET: example -->
069: * </pre>
070: *
071: */
072: @StrutsTag(name="inputtransferselect",tldTagClass="org.apache.struts2.views.jsp.ui.InputTransferSelectTag",description="Renders an input form")
073: public class InputTransferSelect extends ListUIBean {
074:
075: private static final Log _log = LogFactory
076: .getLog(InputTransferSelect.class);
077:
078: private static final String TEMPLATE = "inputtransferselect";
079:
080: protected String size;
081: protected String multiple;
082:
083: protected String allowRemoveAll;
084: protected String allowUpDown;
085:
086: protected String leftTitle;
087: protected String rightTitle;
088:
089: protected String buttonCssClass;
090: protected String buttonCssStyle;
091:
092: protected String addLabel;
093: protected String removeLabel;
094: protected String removeAllLabel;
095: protected String upLabel;
096: protected String downLabel;
097:
098: protected String headerKey;
099: protected String headerValue;
100:
101: public InputTransferSelect(ValueStack stack,
102: HttpServletRequest request, HttpServletResponse response) {
103: super (stack, request, response);
104: }
105:
106: protected String getDefaultTemplate() {
107: return TEMPLATE;
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: // allowUpDown
122: addParameter("allowUpDown", allowUpDown != null ? findValue(
123: allowUpDown, Boolean.class) : Boolean.TRUE);
124:
125: // allowRemoveAll
126: addParameter("allowRemoveAll",
127: allowRemoveAll != null ? findValue(allowRemoveAll,
128: Boolean.class) : Boolean.TRUE);
129:
130: // leftTitle
131: if (leftTitle != null) {
132: addParameter("leftTitle",
133: findValue(leftTitle, String.class));
134: }
135:
136: // rightTitle
137: if (rightTitle != null) {
138: addParameter("rightTitle", findValue(rightTitle,
139: String.class));
140: }
141:
142: // buttonCssClass
143: if (buttonCssClass != null
144: && buttonCssClass.trim().length() > 0) {
145: addParameter("buttonCssClass", buttonCssClass);
146: }
147:
148: // buttonCssStyle
149: if (buttonCssStyle != null
150: && buttonCssStyle.trim().length() > 0) {
151: addParameter("buttonCssStyle", buttonCssStyle);
152: }
153:
154: // addLabel
155: addParameter("addLabel", addLabel != null ? findValue(addLabel,
156: String.class) : "->");
157:
158: // removeLabel
159: addParameter("removeLabel", removeLabel != null ? findValue(
160: removeLabel, String.class) : "<-");
161:
162: // removeAllLabel
163: addParameter("removeAllLabel",
164: removeAllLabel != null ? findValue(removeAllLabel,
165: String.class) : "<<--");
166:
167: // upLabel
168: addParameter("upLabel", upLabel != null ? findValue(upLabel,
169: String.class) : "^");
170:
171: // leftDownLabel
172: addParameter("downLabel", downLabel != null ? findValue(
173: downLabel, String.class) : "v");
174:
175: if ((headerKey != null) && (headerValue != null)) {
176: addParameter("headerKey", findString(headerKey));
177: addParameter("headerValue", findString(headerValue));
178: }
179:
180: // inform the form component our select tag infos, so they know how to select
181: // its elements upon onsubmit
182: Form formAncestor = (Form) findAncestor(Form.class);
183: if (formAncestor != null) {
184:
185: // inform ancestor form that we are having a customOnsubmit (see form-close.ftl [simple theme])
186: enableAncestorFormCustomOnsubmit();
187:
188: // key -> select tag id, value -> headerKey (if exists)
189: Map formInputtransferselectIds = (Map) formAncestor
190: .getParameters().get("inputtransferselectIds");
191:
192: // init lists
193: if (formInputtransferselectIds == null) {
194: formInputtransferselectIds = new LinkedHashMap();
195: }
196:
197: // id
198: String tmpId = (String) getParameters().get("id");
199: String tmpHeaderKey = (String) getParameters().get(
200: "headerKey");
201: if (tmpId != null
202: && (!formInputtransferselectIds.containsKey(tmpId))) {
203: formInputtransferselectIds.put(tmpId, tmpHeaderKey);
204: }
205:
206: formAncestor.getParameters().put("inputtransferselectIds",
207: formInputtransferselectIds);
208:
209: } else {
210: _log
211: .warn("form enclosing inputtransferselect "
212: + this
213: + " not found, auto select upon form submit of inputtransferselect will not work");
214: }
215: }
216:
217: public String getSize() {
218: return size;
219: }
220:
221: @StrutsTagAttribute(description="the size of the select box")
222: public void setSize(String size) {
223: this .size = size;
224: }
225:
226: public String getMultiple() {
227: return multiple;
228: }
229:
230: @StrutsTagAttribute(description="Determine whether or not multiple entries are shown")
231: public void setMultiple(String multiple) {
232: this .multiple = multiple;
233: }
234:
235: public String getAllowRemoveAll() {
236: return allowRemoveAll;
237: }
238:
239: @StrutsTagAttribute(description="Determine whether the remove all button will display")
240: public void setAllowRemoveAll(String allowRemoveAll) {
241: this .allowRemoveAll = allowRemoveAll;
242: }
243:
244: public String getAllowUpDown() {
245: return allowUpDown;
246: }
247:
248: @StrutsTagAttribute(description="Determine whether items in the list can be reordered")
249: public void setAllowUpDown(String allowUpDown) {
250: this .allowUpDown = allowUpDown;
251: }
252:
253: public String getLeftTitle() {
254: return leftTitle;
255: }
256:
257: @StrutsTagAttribute(description="the left hand title")
258: public void setLeftTitle(String leftTitle) {
259: this .leftTitle = leftTitle;
260: }
261:
262: public String getRightTitle() {
263: return rightTitle;
264: }
265:
266: @StrutsTagAttribute(description="the right hand title")
267: public void setRightTitle(String rightTitle) {
268: this .rightTitle = rightTitle;
269: }
270:
271: public String getButtonCssClass() {
272: return buttonCssClass;
273: }
274:
275: @StrutsTagAttribute(description="the css class used for rendering buttons")
276: public void setButtonCssClass(String buttonCssClass) {
277: this .buttonCssClass = buttonCssClass;
278: }
279:
280: public String getButtonCssStyle() {
281: return buttonCssStyle;
282: }
283:
284: @StrutsTagAttribute(description="the css style used for rendering buttons")
285: public void setButtonCssStyle(String buttonCssStyle) {
286: this .buttonCssStyle = buttonCssStyle;
287: }
288:
289: public String getAddLabel() {
290: return addLabel;
291: }
292:
293: @StrutsTagAttribute(description="the label used for the add button")
294: public void setAddLabel(String addLabel) {
295: this .addLabel = addLabel;
296: }
297:
298: public String getRemoveLabel() {
299: return removeLabel;
300: }
301:
302: @StrutsTagAttribute(description="the label used for the remove button")
303: public void setRemoveLabel(String removeLabel) {
304: this .removeLabel = removeLabel;
305: }
306:
307: public String getRemoveAllLabel() {
308: return removeAllLabel;
309: }
310:
311: @StrutsTagAttribute(description="the label used for the remove all button")
312: public void setRemoveAllLabel(String removeAllLabel) {
313: this .removeAllLabel = removeAllLabel;
314: }
315:
316: public String getUpLabel() {
317: return upLabel;
318: }
319:
320: @StrutsTagAttribute(description="the label used for the up button")
321: public void setUpLabel(String upLabel) {
322: this .upLabel = upLabel;
323: }
324:
325: public String getDownLabel() {
326: return downLabel;
327: }
328:
329: @StrutsTagAttribute(description="the label used for the down button")
330: public void setDownLabel(String downLabel) {
331: this .downLabel = downLabel;
332: }
333:
334: public String getHeaderKey() {
335: return headerKey;
336: }
337:
338: @StrutsTagAttribute(description="the header key of the select box")
339: public void setHeaderKey(String headerKey) {
340: this .headerKey = headerKey;
341: }
342:
343: public String getHeaderValue() {
344: return headerValue;
345: }
346:
347: @StrutsTagAttribute(description="the header value of the select box")
348: public void setHeaderValue(String headerValue) {
349: this.headerValue = headerValue;
350: }
351: }
|