KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > taglib > JonasSubmitTag


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer(s): Michel-Ange ANTON
22  * --------------------------------------------------------------------------
23  * $Id: JonasSubmitTag.java,v 1.4 2005/04/01 09:59:04 kemlerp Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.webapp.taglib;
28
29 import javax.servlet.jsp.JspException JavaDoc;
30
31 import org.apache.struts.taglib.TagUtils;
32
33 public class JonasSubmitTag extends JonasButtonTag {
34
35 // -------------------------------------------------------- Instances Variables
36

37     protected String JavaDoc ms_MyFunctionName = null;
38     protected String JavaDoc ms_JavascriptName = null;
39
40 // --------------------------------------------------------- Properties Variables
41

42     private String JavaDoc form = null;
43     private String JavaDoc value = "Apply";
44
45 // --------------------------------------------------------- Properties Methods
46

47     public String JavaDoc getForm() {
48         return form;
49     }
50
51     public void setForm(String JavaDoc form) {
52         this.form = form;
53     }
54
55     public String JavaDoc getValue() {
56         return value;
57     }
58
59     public void setValue(String JavaDoc value) {
60         this.value = value;
61     }
62
63 // --------------------------------------------------------- Public Methods
64

65     /**
66      * Render the beginning.
67      *
68      * @exception JspException if a JSP exception has occurred
69      */

70     public int doStartTag()
71         throws JspException JavaDoc {
72         TagUtils tagUtils = TagUtils.getInstance();
73
74         ms_MyFunctionName = "MySubmit";
75         ms_JavascriptName = "submit";
76
77         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
78         if (getDisabled() == false) {
79             // Add the Javascript begining
80
sb.append(prepareJavascript());
81             //
82
href = prepareCallJavascript();
83         }
84         tagUtils.write(pageContext, sb.toString());
85
86         return (super.doStartTag());
87     }
88
89     /**
90      * Render the end.
91      *
92      * @exception JspException if a JSP exception has occurred
93      */

94     public int doEndTag()
95         throws JspException JavaDoc {
96         // Replace body by value
97
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 // --------------------------------------------------------- Protected Methods
112

113     protected String JavaDoc 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 JavaDoc prepareJavascript() {
123         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
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