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.presentation;
016:
017: import java.io.Writer;
018: import javax.servlet.jsp.JspException;
019: import org.araneaframework.jsp.exception.AraneaJspException;
020: import org.araneaframework.jsp.util.JspUtil;
021: import org.araneaframework.jsp.util.JspWidgetCallUtil;
022:
023: /**
024: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
025: *
026: * @jsp.tag
027: * name = "eventButton"
028: * body-content = "JSP"
029: * description = "Represents an HTML form button."
030: */
031: public class EventButtonHtmlTag extends BaseEventButtonTag {
032: public static final String RENDER_BUTTON = "button";
033: public static final String RENDER_INPUT = "input";
034:
035: {
036: baseStyleClass = "aranea-button";
037: }
038:
039: protected String renderMode = EventButtonHtmlTag.RENDER_BUTTON;
040:
041: protected int doStartTag(Writer out) throws Exception {
042: super .doStartTag(out);
043: // Write button tag
044: JspUtil
045: .writeOpenStartTag(
046: out,
047: renderMode
048: .equals(EventButtonHtmlTag.RENDER_BUTTON) ? EventButtonHtmlTag.RENDER_BUTTON
049: : EventButtonHtmlTag.RENDER_INPUT);
050: if (renderMode.equals(EventButtonHtmlTag.RENDER_INPUT))
051: JspUtil.writeAttribute(out, "type", "button");
052: JspUtil.writeAttribute(out, "id", id);
053: JspUtil.writeAttribute(out, "class", getStyleClass());
054: JspUtil.writeAttribute(out, "style", getStyle());
055: JspUtil.writeAttribute(out, "tabindex", tabindex);
056: JspUtil.writeEventAttributes(out, event);
057:
058: if (isDisabled())
059: out.write(" disabled=\"disabled\" ");
060:
061: if (event.getId() != null) {
062: JspWidgetCallUtil.writeSubmitScriptForEvent(out, "onclick");
063: }
064: if (labelId != null
065: && renderMode.equals(EventButtonHtmlTag.RENDER_INPUT)) {
066: JspUtil.writeAttribute(out, "value", localizedLabel);
067: }
068: if (renderMode.equals(EventButtonHtmlTag.RENDER_BUTTON))
069: JspUtil.writeCloseStartTag_SS(out);
070: if (renderMode.equals(EventButtonHtmlTag.RENDER_INPUT))
071: JspUtil.writeCloseStartEndTag(out);
072:
073: return EVAL_BODY_INCLUDE;
074: }
075:
076: protected int doEndTag(Writer out) throws Exception {
077: if (renderMode.equals(EventButtonHtmlTag.RENDER_BUTTON)) {
078: if (localizedLabel != null)
079: JspUtil.writeEscaped(out, localizedLabel);
080:
081: JspUtil.writeEndTag(out, "button");
082: }
083:
084: super .doEndTag(out);
085: return EVAL_PAGE;
086: }
087:
088: /**
089: * @jsp.attribute
090: * type = "java.lang.String"
091: * required = "false"
092: * description =
093: * "Allowed values are (button | input) - the corresponding HTML tag will be used for rendering. Default is button."
094: */
095: public void setRenderMode(String renderMode) throws JspException {
096: if (!(renderMode.equals(EventButtonHtmlTag.RENDER_BUTTON) || renderMode
097: .equals(EventButtonHtmlTag.RENDER_INPUT)))
098: throw new AraneaJspException(
099: "<ui:eventButton> 'renderMode' attribute must be '"
100: + EventButtonHtmlTag.RENDER_BUTTON
101: + "' or '"
102: + EventButtonHtmlTag.RENDER_INPUT + "'");
103: this .renderMode = (String) evaluate("renderMode", renderMode,
104: String.class);
105: }
106: }
|