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