001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.tag.uilib.form.element.select;
016:
017: import java.io.Writer;
018: import java.util.Iterator;
019: import javax.servlet.jsp.JspException;
020: import org.araneaframework.jsp.tag.basic.AttributedTagInterface;
021: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementHtmlTag;
022: import org.araneaframework.jsp.util.JspUtil;
023: import org.araneaframework.uilib.form.control.MultiSelectControl;
024: import org.araneaframework.uilib.support.DisplayItem;
025:
026: /**
027: * Standard multiselect form element tag.
028: *
029: * @author Oleg Mürk
030: *
031: * @jsp.tag
032: * name = "multiSelect"
033: * body-content = "JSP"
034: * description = "Form list input field, represents UiLib "MultiSelectControl"."
035: */
036: public class FormMultiSelectHtmlTag extends BaseFormElementHtmlTag {
037: protected Long size;
038:
039: {
040: baseStyleClass = "aranea-multi-select";
041: }
042:
043: protected int doStartTag(Writer out) throws Exception {
044: int r = super .doStartTag(out);
045: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
046: return r;
047: }
048:
049: protected int doEndTag(Writer out) throws Exception {
050: assertControlType("MultiSelectControl");
051:
052: // Prepare
053: String name = this .getFullFieldId();
054: MultiSelectControl.ViewModel viewModel = ((MultiSelectControl.ViewModel) controlViewModel);
055:
056: // Write input tag
057: JspUtil.writeOpenStartTag(out, "select");
058: JspUtil.writeAttribute(out, "id", name);
059: JspUtil.writeAttribute(out, "name", name);
060: JspUtil.writeAttribute(out, "class", getStyleClass());
061: JspUtil.writeAttribute(out, "style", getStyle());
062: JspUtil.writeAttribute(out, "multiple", "true");
063: JspUtil.writeAttribute(out, "size", size);
064: JspUtil.writeAttribute(out, "tabindex", tabindex);
065: if (viewModel.isOnChangeEventRegistered())
066: this .writeSubmitScriptForUiEvent(out, "onchange",
067: derivedId, "onChanged", "", updateRegionNames);
068: if (viewModel.isDisabled())
069: JspUtil.writeAttribute(out, "disabled", "true");
070: JspUtil.writeAttributes(out, attributes);
071: writeBackgroundValidationAttribute(out);
072: JspUtil.writeCloseStartTag(out);
073:
074: for (Iterator i = viewModel.getSelectItems().iterator(); i
075: .hasNext();) {
076: DisplayItem item = (DisplayItem) i.next();
077: String value = item.getValue();
078: String label = item.getDisplayString();
079:
080: JspUtil.writeOpenStartTag(out, "option");
081: JspUtil.writeAttribute(out, "value", value != null ? value
082: : "");
083: if (viewModel.getValueSet().contains(value))
084: JspUtil.writeAttribute(out, "selected", "true");
085: JspUtil.writeCloseStartTag_SS(out);
086: JspUtil.writeEscaped(out, label);
087: JspUtil.writeEndTag(out, "option");
088: }
089:
090: // Close tag
091: JspUtil.writeEndTag_SS(out, "select");
092:
093: super .doEndTag(out);
094: return EVAL_PAGE;
095: }
096:
097: //
098: // Attributes
099: //
100:
101: /**
102: * @jsp.attribute
103: * type = "java.lang.String"
104: * required = "false"
105: * description = "Vertical size, number of options displayed."
106: */
107: public void setSize(String size) throws JspException {
108: this .size = (Long) evaluate("size", size, Long.class);
109: }
110: }
|