00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00036
00037 protected String ms_MyFunctionName = null;
00038 protected String ms_JavascriptName = null;
00039
00040
00041
00042 private String form = null;
00043 private String value = "Apply";
00044
00045
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
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
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
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
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 }