1 26 27 package org.objectweb.jonas.webapp.taglib; 28 29 import javax.servlet.jsp.JspException ; 30 31 import org.apache.struts.taglib.TagUtils; 32 33 public class JonasSubmitTag extends JonasButtonTag { 34 35 37 protected String ms_MyFunctionName = null; 38 protected String ms_JavascriptName = null; 39 40 42 private String form = null; 43 private String value = "Apply"; 44 45 47 public String getForm() { 48 return form; 49 } 50 51 public void setForm(String form) { 52 this.form = form; 53 } 54 55 public String getValue() { 56 return value; 57 } 58 59 public void setValue(String value) { 60 this.value = value; 61 } 62 63 65 70 public int doStartTag() 71 throws JspException { 72 TagUtils tagUtils = TagUtils.getInstance(); 73 74 ms_MyFunctionName = "MySubmit"; 75 ms_JavascriptName = "submit"; 76 77 StringBuffer sb = new StringBuffer (); 78 if (getDisabled() == false) { 79 sb.append(prepareJavascript()); 81 href = prepareCallJavascript(); 83 } 84 tagUtils.write(pageContext, sb.toString()); 85 86 return (super.doStartTag()); 87 } 88 89 94 public int doEndTag() 95 throws JspException { 96 if (value != null) { 98 text = value; 99 } 100 return super.doEndTag(); 101 } 102 103 public void release() { 104 super.release(); 105 form = null; 106 value = null; 107 ms_MyFunctionName = null; 108 ms_JavascriptName = null; 109 } 110 111 113 protected String prepareCallJavascript() { 114 if (form == null) { 115 return "javascript:" + ms_MyFunctionName + "()"; 116 } 117 else { 118 return "javascript:" + ms_MyFunctionName + form + "()"; 119 } 120 } 121 122 protected String prepareJavascript() { 123 StringBuffer sb = new StringBuffer (); 124 sb.append("<script language=\"JavaScript\" type=\"text/javascript\">"); 125 sb.append("function "); 126 if (form == null) { 127 sb.append(ms_MyFunctionName).append("() {document.forms[0]." + ms_JavascriptName 128 + "();}"); 129 } 130 else { 131 sb.append(ms_MyFunctionName); 132 sb.append(form); 133 sb.append("() {document."); 134 sb.append(form); 135 sb.append("." + ms_JavascriptName + "();}"); 136 } 137 sb.append("</script>"); 138 139 return sb.toString(); 140 } 141 } | Popular Tags |