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.form;
016:
017: import java.io.Writer;
018: import javax.servlet.http.HttpServletResponse;
019: import javax.servlet.jsp.JspException;
020: import org.araneaframework.jsp.exception.AraneaJspException;
021: import org.araneaframework.jsp.tag.BaseTag;
022: import org.araneaframework.jsp.util.JspUtil;
023:
024: /**
025: * Abstract base class for systemForm tags. System form maps into HTML form.
026: *
027: * @author Oleg Mürk
028: */
029: public abstract class BaseSystemFormHtmlTag extends BaseTag {
030:
031: public final static String GET_METHOD = "get";
032: public final static String POST_METHOD = "post";
033:
034: private String id = null;
035: protected String derivedId = null;
036: protected String method = null;
037: protected String enctype = null;
038: protected String styleClass = null;
039:
040: protected int doStartTag(Writer out) throws Exception {
041: super .doStartTag(out);
042:
043: // Compute new id for systemForm.
044: derivedId = id == null ? "systemForm" : id;
045:
046: // Write form
047: JspUtil.writeOpenStartTag(out, "form");
048: JspUtil.writeAttribute(out, "id", derivedId);
049: JspUtil.writeAttribute(out, "name", derivedId);
050: JspUtil.writeAttribute(out, "method", method);
051: JspUtil.writeAttribute(out, "enctype", enctype);
052: JspUtil.writeAttribute(out, "accept-charset",
053: getAcceptCharset());
054: JspUtil.writeAttribute(out, "action",
055: ((HttpServletResponse) pageContext.getResponse())
056: .encodeURL(getFormAction()));
057: if (styleClass != null)
058: JspUtil.writeAttribute(out, "class", styleClass);
059: JspUtil.writeAttribute(out, "style", "margin: 0px");
060: JspUtil.writeAttribute(out, "onsubmit", "return false;");
061: JspUtil.writeAttribute(out, "arn-systemForm", "true");
062: JspUtil.writeCloseStartTag(out);
063:
064: return EVAL_BODY_INCLUDE;
065: }
066:
067: protected int doEndTag(Writer out) throws Exception {
068: JspUtil.writeEndTag(out, "form");
069:
070: // Continue
071: super .doEndTag(out);
072: return EVAL_PAGE;
073: }
074:
075: /* ***********************************************************************************
076: * Tag attributes
077: * ***********************************************************************************/
078: /**
079: * @jsp.attribute
080: * type = "java.lang.String"
081: * required = "false"
082: * description = "Form name, autogenerated if omitted."
083: */
084: public void setId(String id) throws JspException {
085: this .id = (String) evaluate("id", id, String.class);
086: }
087:
088: /**
089: * @jsp.attribute
090: * type = "java.lang.String"
091: * required = "true"
092: * description = "Submitting method: GET or POST."
093: */
094: public void setMethod(String method) throws JspException {
095: this .method = ((String) evaluateNotNull("method", method,
096: String.class)).toLowerCase();
097:
098: if (!this .method.equals(GET_METHOD)
099: && !this .method.equals(POST_METHOD))
100: throw new AraneaJspException("Wrong form method value '"
101: + method + "'");
102: }
103:
104: /**
105: * @jsp.attribute
106: * type = "java.lang.String"
107: * required = "false"
108: * description = "Form data encoding type."
109: */
110: public void setEnctype(String enctype) throws JspException {
111: this .enctype = (String) evaluate("enctype", enctype,
112: String.class);
113: }
114:
115: /**
116: * @jsp.attribute
117: * type = "java.lang.String"
118: * required = "false"
119: * description = "CSS class for tag"
120: */
121: public void setStyleClass(String styleClass) throws JspException {
122: this .styleClass = (String) evaluate("styleClass", styleClass,
123: String.class);
124: }
125:
126: /* ***********************************************************************************
127: * ABSTRACT METHODS
128: * ***********************************************************************************/
129:
130: protected abstract String getAcceptCharset();
131:
132: protected abstract String getFormAction() throws JspException;
133: }
|