JonasSubmitTag.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): Michel-Ange ANTON
00022  * --------------------------------------------------------------------------
00023  * $Id: JonasSubmitTag.java,v 1.3 2003/06/20 17:15:42 antonma Exp $
00024  * --------------------------------------------------------------------------
00025  */
00026 
00027 package org.objectweb.jonas.webapp.taglib;
00028 
00029 import javax.servlet.jsp.JspException;
00030 
00031 import org.apache.struts.util.ResponseUtils;
00032 
00033 public class JonasSubmitTag extends JonasButtonTag {
00034 
00035 // --------------------------------------------------------  Instances Variables
00036 
00037     protected String ms_MyFunctionName = null;
00038     protected String ms_JavascriptName = null;
00039 
00040 // --------------------------------------------------------- Properties Variables
00041 
00042     private String form = null;
00043     private String value = "Apply";
00044 
00045 // --------------------------------------------------------- Properties Methods
00046 
00047     public String getForm() {
00048         return form;
00049     }
00050 
00051     public void setForm(String form) {
00052         this.form = form;
00053     }
00054 
00055     public String getValue() {
00056         return value;
00057     }
00058 
00059     public void setValue(String value) {
00060         this.value = value;
00061     }
00062 
00063 // --------------------------------------------------------- Public Methods
00064 
00070     public int doStartTag()
00071         throws JspException {
00072 
00073         ms_MyFunctionName = "MySubmit";
00074         ms_JavascriptName = "submit";
00075 
00076         StringBuffer sb = new StringBuffer();
00077         if (getDisabled() == false) {
00078             // Add the Javascript begining
00079             sb.append(prepareJavascript());
00080             //
00081             href = prepareCallJavascript();
00082         }
00083         ResponseUtils.write(pageContext, sb.toString());
00084 
00085         return (super.doStartTag());
00086     }
00087 
00093     public int doEndTag()
00094         throws JspException {
00095         // Replace body by value
00096         if (value != null) {
00097             text = value;
00098         }
00099         return super.doEndTag();
00100     }
00101 
00102     public void release() {
00103         super.release();
00104         form = null;
00105         value = null;
00106         ms_MyFunctionName = null;
00107         ms_JavascriptName = null;
00108     }
00109 
00110 // --------------------------------------------------------- Protected Methods
00111 
00112     protected String prepareCallJavascript() {
00113         if (form == null) {
00114             return "javascript:" + ms_MyFunctionName + "()";
00115         }
00116         else {
00117             return "javascript:" + ms_MyFunctionName + form + "()";
00118         }
00119     }
00120 
00121     protected String prepareJavascript() {
00122         StringBuffer sb = new StringBuffer();
00123         sb.append("<script language=\"JavaScript\" type=\"text/javascript\">");
00124         sb.append("function ");
00125         if (form == null) {
00126             sb.append(ms_MyFunctionName).append("() {document.forms[0]." + ms_JavascriptName
00127                 + "();}");
00128         }
00129         else {
00130             sb.append(ms_MyFunctionName);
00131             sb.append(form);
00132             sb.append("() {document.");
00133             sb.append(form);
00134             sb.append("." + ms_JavascriptName + "();}");
00135         }
00136         sb.append("</script>");
00137 
00138         return sb.toString();
00139     }
00140 }

Generated on Tue Feb 15 15:05:34 2005 for JOnAS by  doxygen 1.3.9.1