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.SelectControl;
024:
025: /**
026: * Standard radio select item form element tag.
027: *
028: * @author Oleg Mürk
029: *
030: * @jsp.tag
031: * name = "radioSelectItem"
032: * body-content = "JSP"
033: * description = "Form radio button, represents one item from UiLib "SelectControl"."
034: */
035: public class FormRadioSelectItemHtmlTag extends BaseFormElementHtmlTag {
036: protected String value;
037: protected String onChangePrecondition;
038: protected String htmlId;
039:
040: {
041: baseStyleClass = "aranea-radio";
042: }
043:
044: protected int doStartTag(Writer out) throws Exception {
045: int result = super .doStartTag(out);
046: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
047: return result;
048: }
049:
050: protected int doEndTag(Writer out) throws Exception {
051: assertControlType("SelectControl");
052:
053: // Prepare
054: String name = this .getFullFieldId();
055: SelectControl.ViewModel viewModel = ((SelectControl.ViewModel) controlViewModel);
056:
057: // Write input tag
058: String selectedValue = viewModel.getSimpleValue();
059: boolean selected = (selectedValue == null && value == null)
060: || (selectedValue != null && selectedValue
061: .equals(value));
062:
063: if (!viewModel.containsItem(value)) {
064: throw new AraneaJspException("Value '" + value
065: + "' not found in values list.");
066: }
067:
068: JspUtil.writeOpenStartTag(out, "input");
069: JspUtil.writeAttribute(out, "id", htmlId);
070: JspUtil.writeAttribute(out, "name", name);
071: JspUtil.writeAttribute(out, "class", getStyleClass());
072: JspUtil.writeAttribute(out, "style", getStyle());
073: JspUtil.writeAttribute(out, "type", "radio");
074: JspUtil.writeAttribute(out, "value", value);
075: JspUtil.writeAttribute(out, "tabindex", tabindex);
076: if (viewModel.isDisabled()
077: || viewModel.getSelectItemByValue(value).isDisabled())
078: JspUtil.writeAttribute(out, "disabled", "disabled");
079: if (selected)
080: JspUtil.writeAttribute(out, "checked", "checked");
081: if (events && viewModel.isOnChangeEventRegistered())
082: this .writeSubmitScriptForUiEvent(out, "onclick", derivedId,
083: "onChanged", onChangePrecondition,
084: updateRegionNames);
085: JspUtil.writeAttributes(out, attributes);
086: JspUtil.writeCloseStartEndTag_SS(out);
087:
088: super .doEndTag(out);
089: return EVAL_PAGE;
090: }
091:
092: /* ***********************************************************************************
093: * Tag attributes
094: * ***********************************************************************************/
095:
096: /**
097: * @jsp.attribute
098: * type = "java.lang.String"
099: * required = "false"
100: * description = "The value of this radio button that will be submitted with form if this radio button is selected."
101: */
102: public void setValue(String value) throws JspException {
103: this .value = (String) evaluateNotNull("value", value,
104: String.class);
105: }
106:
107: /**
108: * @jsp.attribute
109: * type = "java.lang.String"
110: * required = "false"
111: * description = "The HTML id this radio button."
112: * @since 1.1
113: */
114: public void setHtmlId(String htmlId) throws JspException {
115: this .htmlId = (String) evaluate("htmlId", htmlId, String.class);
116: }
117:
118: /**
119: * @jsp.attribute
120: * type = "java.lang.String"
121: * required = "false"
122: * description = "Precondition for deciding whether go to server side or not."
123: */
124: public void setOnChangePrecondition(String onChangePrecondition)
125: throws JspException {
126: this .onChangePrecondition = (String) evaluate(
127: "onChangePrecondition", onChangePrecondition,
128: String.class);
129: }
130: }
|