001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): Michel-Ange ANTON
022: * --------------------------------------------------------------------------
023: * $Id: JonasSubmitTag.java 6499 2005-04-01 09:59:04Z kemlerp $
024: * --------------------------------------------------------------------------
025: */
026:
027: package org.objectweb.jonas.webapp.taglib;
028:
029: import javax.servlet.jsp.JspException;
030:
031: import org.apache.struts.taglib.TagUtils;
032:
033: public class JonasSubmitTag extends JonasButtonTag {
034:
035: // -------------------------------------------------------- Instances Variables
036:
037: protected String ms_MyFunctionName = null;
038: protected String ms_JavascriptName = null;
039:
040: // --------------------------------------------------------- Properties Variables
041:
042: private String form = null;
043: private String value = "Apply";
044:
045: // --------------------------------------------------------- Properties Methods
046:
047: public String getForm() {
048: return form;
049: }
050:
051: public void setForm(String form) {
052: this .form = form;
053: }
054:
055: public String getValue() {
056: return value;
057: }
058:
059: public void setValue(String value) {
060: this .value = value;
061: }
062:
063: // --------------------------------------------------------- Public Methods
064:
065: /**
066: * Render the beginning.
067: *
068: * @exception JspException if a JSP exception has occurred
069: */
070: public int doStartTag() throws JspException {
071: TagUtils tagUtils = TagUtils.getInstance();
072:
073: ms_MyFunctionName = "MySubmit";
074: ms_JavascriptName = "submit";
075:
076: StringBuffer sb = new StringBuffer();
077: if (getDisabled() == false) {
078: // Add the Javascript begining
079: sb.append(prepareJavascript());
080: //
081: href = prepareCallJavascript();
082: }
083: tagUtils.write(pageContext, sb.toString());
084:
085: return (super .doStartTag());
086: }
087:
088: /**
089: * Render the end.
090: *
091: * @exception JspException if a JSP exception has occurred
092: */
093: public int doEndTag() throws JspException {
094: // Replace body by value
095: if (value != null) {
096: text = value;
097: }
098: return super .doEndTag();
099: }
100:
101: public void release() {
102: super .release();
103: form = null;
104: value = null;
105: ms_MyFunctionName = null;
106: ms_JavascriptName = null;
107: }
108:
109: // --------------------------------------------------------- Protected Methods
110:
111: protected String prepareCallJavascript() {
112: if (form == null) {
113: return "javascript:" + ms_MyFunctionName + "()";
114: } else {
115: return "javascript:" + ms_MyFunctionName + form + "()";
116: }
117: }
118:
119: protected String prepareJavascript() {
120: StringBuffer sb = new StringBuffer();
121: sb
122: .append("<script language=\"JavaScript\" type=\"text/javascript\">");
123: sb.append("function ");
124: if (form == null) {
125: sb.append(ms_MyFunctionName).append(
126: "() {document.forms[0]." + ms_JavascriptName
127: + "();}");
128: } else {
129: sb.append(ms_MyFunctionName);
130: sb.append(form);
131: sb.append("() {document.");
132: sb.append(form);
133: sb.append("." + ms_JavascriptName + "();}");
134: }
135: sb.append("</script>");
136:
137: return sb.toString();
138: }
139: }
|