KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jcorporate > expresso > ext > struts > taglib > html > ExRadioLayerTag


1 /* ====================================================================
2  * The Jcorporate Apache Style Software License, Version 1.2 05-07-2002
3  *
4  * Copyright (c) 1995-2002 Jcorporate Ltd. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution,
19  * if any, must include the following acknowledgment:
20  * "This product includes software developed by Jcorporate Ltd.
21  * (http://www.jcorporate.com/)."
22  * Alternately, this acknowledgment may appear in the software itself,
23  * if and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. "Jcorporate" and product names such as "Expresso" must
26  * not be used to endorse or promote products derived from this
27  * software without prior written permission. For written permission,
28  * please contact info@jcorporate.com.
29  *
30  * 5. Products derived from this software may not be called "Expresso",
31  * or other Jcorporate product names; nor may "Expresso" or other
32  * Jcorporate product names appear in their name, without prior
33  * written permission of Jcorporate Ltd.
34  *
35  * 6. No product derived from this software may compete in the same
36  * market space, i.e. framework, without prior written permission
37  * of Jcorporate Ltd. For written permission, please contact
38  * partners@jcorporate.com.
39  *
40  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43  * DISCLAIMED. IN NO EVENT SHALL JCORPORATE LTD OR ITS CONTRIBUTORS
44  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
46  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51  * SUCH DAMAGE.
52  * ====================================================================
53  *
54  * This software consists of voluntary contributions made by many
55  * individuals on behalf of the Jcorporate Ltd. Contributions back
56  * to the project(s) are encouraged when you make modifications.
57  * Please send them to support@jcorporate.com. For more information
58  * on Jcorporate Ltd. and its products, please see
59  * <http://www.jcorporate.com/>.
60  *
61  * Portions of this software are based upon other open source
62  * products and are subject to their respective licenses.
63  */

64
65 package com.jcorporate.expresso.ext.struts.taglib.html;
66
67 /*
68  * ExRadioLayerTag.java
69  *
70  * Copyright 2002, 2002 Yves Henri AMAIZO.
71  * amy_amaizo@compuserve.com
72  */

73
74 import com.jcorporate.expresso.core.misc.StringUtil;
75
76 import javax.servlet.jsp.JspException JavaDoc;
77
78 /**
79  *
80  * Sample:
81  * <code>
82  * <%@taglib uri="/WEB-INF/tld/expresso.tld" prefix="expresso"%>
83  * <%@taglib uri="/WEB-INF/tld/expresso-html.tld" prefix="html"%>
84  * <html:html locale="true">
85  * <head>
86  * <TITLE>Sample TagLib Layer</TITLE>
87  * </head>
88  * <body>
89  * <html:form action="/expresso/Test.do">
90  * <table border="0" bgcolor="red">
91  * <tr>
92  * <TD width="10">Titre1</TD>
93  * <TD align="left" width="10"><html:radioLayer property="toto" id="titi" action="show" value="Oui"/>Oui</TD>
94  * <TD width="100%"align="left"><html:radioLayer property="toto" id="titi" action="hide" value="Non"/>Non</TD>
95  * </tr>
96  * <TR height="1">
97  * <TD colspan="3" height="1">
98  * <html:layer id="titi" state="hide">
99  * <table border="0" bgcolor="GREEN">
100  * <tr>
101  * <TD bgcolor="WHITE">Titre2</TD>
102  * <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="show" value="Oui"/>Oui</TD>
103  * <TD bgcolor="WHITE"><html:radioLayer property="toto" id="titi2" action="hide" value="Non"/>Non</TD>
104  * </tr>
105  * <tr height="1" bgcolor="WHITE">
106  * <TD height="1" colspan="3" bgcolor="WHITE"><html:layer id="titi2" state="hide"><expresso:InputTag name="toto"/></html:layer></TD>
107  * </tr>
108  * </table>
109  * </html:layer>
110  * </TD>
111  * </tr>
112  * </table>
113  * </html:form>
114  * </body>
115  * </html:html>
116  * </code>
117  *
118  */

119
120
121 /**
122  * Tag for input fields of type "RadioLayer".
123  *
124  * @author Yves Henri AMAIZO
125  */

126 public class ExRadioLayerTag extends ExRadioTag {
127
128     private static String JavaDoc STR_JS_LAYER = "%action%%id%(\'%type%\');";
129
130     private String JavaDoc id = "";
131
132     private static String JavaDoc SHOW_JS = "showLayer";
133
134     private static String JavaDoc HIDE_JS = "hideLayer";
135
136     private static String JavaDoc EXPAND = "EXPAND";
137
138     private static String JavaDoc COLLAPSE = "COLLAPSE";
139
140     private String JavaDoc action = HIDE_JS;
141
142     private String JavaDoc node = EXPAND;
143
144
145     /**
146      * Generate the required input tag.
147      *
148      * @throws JspException if a JSP exception has occurred
149      */

150     public int doStartTag() throws JspException JavaDoc {
151         String JavaDoc onClick = STR_JS_LAYER;
152         onClick += StringUtil.notNull(getOnclick());
153         onClick = StringUtil.replaceString(onClick, "%id%", id);
154         onClick = StringUtil.replaceString(onClick, "%action%", action);
155         onClick = StringUtil.replaceString(onClick, "%type%", node);
156         super.setOnclick(onClick);
157         return super.doStartTag();
158     }
159
160     /**
161      * Gets the id
162      *
163      * @return Returns a String
164      */

165     public String JavaDoc getId() {
166         return id;
167     }
168
169     /**
170      * Sets the id
171      *
172      * @param id The id to set
173      */

174     public void setId(String JavaDoc id) {
175         this.id = id;
176     }
177
178
179     /**
180      * Gets the action
181      *
182      * @return Returns a String
183      */

184     public String JavaDoc getAction() {
185         return action;
186     }
187
188     /**
189      * Sets the action
190      *
191      * @param action The action to set
192      */

193     public void setAction(String JavaDoc action) throws JspException JavaDoc {
194         if (action.equalsIgnoreCase("SHOW")) {
195             this.action = SHOW_JS;
196         } else {
197             if (action.equalsIgnoreCase("HIDE")) {
198                 this.action = HIDE_JS;
199             } else {
200                 throw new JspException JavaDoc("action must be 'Show' or 'Hide'");
201             }
202         }
203     }
204
205
206     /**
207      * Gets the node
208      *
209      * @return Returns a String
210      */

211     public String JavaDoc getNode() {
212         return node;
213     }
214
215     /**
216      * Sets the node
217      *
218      * @param node The node to set
219      */

220     public void setNode(String JavaDoc node) throws JspException JavaDoc {
221         if (node.equalsIgnoreCase(EXPAND)) {
222             this.node = EXPAND;
223         } else {
224             if (node.equalsIgnoreCase(COLLAPSE)) {
225                 this.node = COLLAPSE;
226             } else {
227                 throw new JspException JavaDoc("node must be 'collapse' or 'expand'");
228             }
229         }
230     }
231
232
233 }
234
235
236
Popular Tags