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.text;
016:
017: import java.io.Writer;
018: import java.util.HashMap;
019: import java.util.Iterator;
020: import java.util.Map;
021: import javax.servlet.jsp.JspException;
022: import org.araneaframework.jsp.tag.basic.AttributedTagInterface;
023: import org.araneaframework.jsp.tag.uilib.form.BaseFormElementHtmlTag;
024: import org.araneaframework.jsp.util.JspUtil;
025: import org.araneaframework.uilib.form.control.StringArrayRequestControl;
026:
027: /**
028: * Standard text input form element base tag.
029: *
030: * @author Oleg Mürk
031: */
032: public class BaseFormTextInputHtmlTag extends BaseFormElementHtmlTag {
033: protected Long size;
034: protected String onChangePrecondition;
035:
036: {
037: baseStyleClass = "aranea-text";
038: }
039:
040: protected int doStartTag(Writer out) throws Exception {
041: int result = super .doStartTag(out);
042: addContextEntry(AttributedTagInterface.HTML_ELEMENT_KEY, null);
043: return result;
044: }
045:
046: /* ***********************************************************************************
047: * Tag attributes
048: * ***********************************************************************************/
049: /**
050: * @jsp.attribute
051: * type = "java.lang.String"
052: * required = "false"
053: * description = "Horizontal size, in characters."
054: */
055: public void setSize(String size) throws JspException {
056: this .size = (Long) evaluate("size", size, Long.class);
057: }
058:
059: /**
060: * @jsp.attribute
061: * type = "java.lang.String"
062: * required = "false"
063: * description = "Precondition for deciding whether go to server side or not."
064: */
065: public void setOnChangePrecondition(String onChangePrecondition)
066: throws JspException {
067: this .onChangePrecondition = (String) evaluate(
068: "onChangePrecondition", onChangePrecondition,
069: String.class);
070: }
071:
072: /* ***********************************************************************************
073: * INPUT writing functions
074: * ***********************************************************************************/
075:
076: protected void writeTextInput(Writer out, String inputType)
077: throws Exception {
078: writeTextInput(out, inputType, true, new HashMap());
079: }
080:
081: protected void writeTextInput(Writer out, String inputType,
082: boolean writeValue, Map customAttributes) throws Exception {
083: String name = this .getFullFieldId();
084: StringArrayRequestControl.ViewModel viewModel = ((StringArrayRequestControl.ViewModel) controlViewModel);
085:
086: // Write
087: JspUtil.writeOpenStartTag(out, "input");
088: JspUtil.writeAttribute(out, "id", name);
089: JspUtil.writeAttribute(out, "name", name);
090: JspUtil.writeAttribute(out, "class", getStyleClass());
091: JspUtil.writeAttribute(out, "style", getStyle());
092: JspUtil.writeAttribute(out, "type", inputType);
093: if (writeValue)
094: JspUtil.writeAttribute(out, "value", viewModel
095: .getSimpleValue());
096: JspUtil.writeAttribute(out, "size", size);
097: JspUtil.writeAttribute(out, "tabindex", tabindex);
098:
099: writeBackgroundValidationAttribute(out);
100:
101: for (Iterator i = customAttributes.entrySet().iterator(); i
102: .hasNext();) {
103: Map.Entry attribute = (Map.Entry) i.next();
104:
105: JspUtil.writeAttribute(out, "" + attribute.getKey(),
106: attribute.getValue());
107: }
108:
109: if (viewModel.isDisabled())
110: JspUtil.writeAttribute(out, "disabled", "true");
111: if (events && viewModel.isOnChangeEventRegistered()) {
112: // We use "onblur" to simulate the textbox's "onchange" event
113: // this is _not_ good, but there seems to be no other way
114: JspUtil.writeAttribute(out, "onfocus",
115: "Aranea.UI.saveValue(this)");
116: if (onChangePrecondition == null)
117: onChangePrecondition = "return Aranea.UI.isChanged('"
118: + name + "');";
119: this .writeSubmitScriptForUiEvent(out, "onblur", derivedId,
120: "onChanged", onChangePrecondition,
121: updateRegionNames);
122: }
123: JspUtil.writeAttributes(out, attributes);
124: JspUtil.writeCloseStartEndTag_SS(out);
125: }
126:
127: public void doFinally() {
128: super.doFinally();
129: onChangePrecondition = null;
130: }
131: }
|