01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.jsp.tag.uilib.form.element.select;
16:
17: import java.io.IOException;
18: import java.io.Writer;
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22: import org.araneaframework.jsp.exception.AraneaJspException;
23: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementDisplayTag;
24: import org.araneaframework.jsp.util.JspUtil;
25: import org.araneaframework.uilib.form.control.MultiSelectControl;
26: import org.araneaframework.uilib.support.DisplayItem;
27:
28: /**
29: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
30: *
31: * @jsp.tag
32: * name = "multiSelectDisplay"
33: * body-content = "JSP"
34: * description = "Form multiselect display field, represents UiLib "MultiSelectControl"."
35: */
36: public class FormMultiSelectDisplayHtmlTag extends
37: BaseFormElementDisplayTag {
38: protected static final String NEWLINE_SEPARATOR_CODE = "\\n";
39: protected String separator = ", ";
40:
41: {
42: baseStyleClass = "aranea-multi-select-display";
43: }
44:
45: protected int doEndTag(Writer out) throws Exception {
46: MultiSelectControl.ViewModel viewModel = ((MultiSelectControl.ViewModel) controlViewModel);
47:
48: JspUtil.writeOpenStartTag(out, "span");
49: JspUtil.writeAttribute(out, "class", getStyleClass());
50: JspUtil.writeAttribute(out, "style", getStyle());
51: JspUtil.writeAttributes(out, attributes);
52: JspUtil.writeCloseStartTag(out);
53:
54: List selectedItems = new ArrayList(viewModel.getSelectItems());
55: for (Iterator i = selectedItems.iterator(); i.hasNext();) {
56: DisplayItem displayItem = (DisplayItem) i.next();
57: if (!viewModel.getValueSet().contains(
58: displayItem.getValue()))
59: i.remove();
60: }
61:
62: for (Iterator i = selectedItems.iterator(); i.hasNext();) {
63: DisplayItem displayItem = (DisplayItem) i.next();
64:
65: JspUtil.writeEscaped(out, displayItem.getDisplayString());
66: if (i.hasNext())
67: writeSeparator(out);
68: }
69:
70: return super .doEndTag(out);
71: }
72:
73: /**
74: * @jsp.attribute
75: * type = "java.lang.String"
76: * required = "false"
77: * description = "The separator between list items, can be any string and '\n', meaning a newline (by default ', ')."
78: */
79: public void setSeparator(String separator) {
80: this .separator = separator;
81: }
82:
83: protected void writeSeparator(Writer out) throws IOException,
84: AraneaJspException {
85: if (NEWLINE_SEPARATOR_CODE.equals(separator))
86: JspUtil.writeStartEndTag(out, "br");
87: else
88: out.write(separator);
89: }
90: }
|