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 javax.servlet.jsp.JspException;
019: import org.araneaframework.jsp.exception.AraneaJspException;
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:
025: /**
026: * Form multiselect rendering tag, represents one item from {@link org.araneaframework.uilib.form.control.MultiSelectControl}.
027: * Default <code>styleClass</code> is "aranea-multi-checkbox".
028: * It will be rendered with HTML <input type="checkbox"> tag.
029: *
030: * @author Oleg Mürk
031: * @author Jevgeni Kabanov
032: * <br>
033: * @jsp.tag
034: * name = "checkboxMultiSelectItem"
035: * body-content = "JSP"
036: * description = "Form checkbox, represents one item from UiLib 'MultiSelectControl' rendered with checkboxes."
037: */
038: public class FormCheckboxMultiSelectItemHtmlTag extends
039: BaseFormElementHtmlTag {
040: protected String value;
041: /** @since 1.1 */
042: protected String htmlId;
043:
044: {
045: baseStyleClass = "aranea-multi-checkbox";
046: }
047:
048: protected int doStartTag(Writer out) throws Exception {
049: int r = super .doStartTag(out);
050: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
051: return r;
052: }
053:
054: protected int doEndTag(Writer out) throws Exception {
055: // Type check
056: assertControlType("MultiSelectControl");
057:
058: // Prepare
059: String name = this .getFullFieldId();
060: MultiSelectControl.ViewModel viewModel = ((MultiSelectControl.ViewModel) controlViewModel);
061:
062: if (viewModel.getSelectItemByValue(value) == null)
063: throw new AraneaJspException("Value '" + value
064: + "' not found in values list.");
065:
066: JspUtil.writeOpenStartTag(out, "input");
067: JspUtil.writeAttribute(out, "id", htmlId);
068: JspUtil.writeAttribute(out, "name", name);
069: JspUtil.writeAttribute(out, "class", getStyleClass());
070: JspUtil.writeAttribute(out, "style", getStyle());
071: JspUtil.writeAttribute(out, "type", "checkbox");
072: JspUtil.writeAttribute(out, "value", value);
073: JspUtil.writeAttribute(out, "tabindex", tabindex);
074:
075: if (viewModel.isDisabled()
076: || viewModel.getSelectItemByValue(value).isDisabled())
077: JspUtil.writeAttribute(out, "disabled", "true");
078:
079: if (viewModel.getValueSet().contains(value))
080: JspUtil.writeAttribute(out, "checked", "true");
081:
082: JspUtil.writeAttributes(out, attributes);
083:
084: if (events && viewModel.isOnChangeEventRegistered())
085: this .writeSubmitScriptForUiEvent(out, "onclick", derivedId,
086: "onChanged", "", updateRegionNames);
087:
088: writeBackgroundValidationAttribute(out);
089:
090: JspUtil.writeCloseStartEndTag_SS(out);
091:
092: // Continue
093: super .doEndTag(out);
094: return EVAL_PAGE;
095: }
096:
097: /**
098: * @jsp.attribute
099: * type = "java.lang.String"
100: * required = "false"
101: * description = "The value of this checkbox that will be submitted with form if this checkbox is selected."
102: */
103: public void setValue(String value) throws JspException {
104: this .value = (String) evaluateNotNull("value", value,
105: String.class);
106: }
107:
108: /**
109: * @jsp.attribute
110: * type = "java.lang.String"
111: * required = "false"
112: * description = "Sets the HTML id of this checkbox button."
113: * @since 1.1
114: */
115: public void setHtmlId(String htmlId) throws JspException {
116: this .htmlId = (String) evaluate("htmlId", htmlId, String.class);
117: }
118: }
|