KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ExLayerInputTag.java
69  *
70  * Copyright 2002, 2002 Yves Henri AMAIZO.
71  * amy_amaizo@compuserve.com
72  */

73
74 import com.jcorporate.expresso.core.controller.Input;
75 import com.jcorporate.expresso.core.misc.StringUtil;
76 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils;
77 import org.apache.struts.util.ResponseUtils;
78
79 import javax.servlet.jsp.JspException JavaDoc;
80 import java.util.Iterator JavaDoc;
81 import java.util.List JavaDoc;
82 import java.util.Vector JavaDoc;
83
84
85 /**
86  *
87  * <%@taglib uri="/WEB-INF/tld/expresso.tld" prefix="expresso"%>
88  * <%@taglib uri="/WEB-INF/tld/expresso-html.tld" prefix="html"%>
89  * <%@taglib uri="/WEB-INF/tld/expresso-logic.tld" prefix="logic"%>
90  * <html:html locale="true">
91  * <head>
92  * <TITLE>Sample TagLib collapse Layer</TITLE>
93  * </head>
94  * <body>
95  * <html:form action="/expresso/Test.do">
96  *
97  * <table border="0" bgcolor="black" width="100%">
98  * <tr>
99  * <td nowrap bgcolor="WHITE">
100  * <table border = "0">
101  * <tr>
102  * <TD width="100" nowrap >answer question</TD>
103  * <TD width="100" nowrap align="left" ><html:radioLayer property="swapp" id="look" action="show" value="Yes" node="collapse"/>Yes</TD>
104  * <TD width="100" nowrap align="left"><html:radioLayer property="swapp" id="look" action="hide" value="No"/>No</TD>
105  * <TD>
106  * <html:layer id="look" property="swapp" value="Yes">
107  * <html:remoteLayer id="titi2" action="show">display</html:remoteLayer>/<html:remoteLayer id="titi2" action="hide">close</html:remoteLayer>
108  * </html:layer>
109  * </TD>
110  * </tr>
111  * </table>
112  * <html:layer id="titi2" state="hide">
113  * <table border="0" bgcolor="black" width="100%">
114  * <tr>
115  * <TD width="200" nowrap bgcolor="WHITE">Question details</TD>
116  * <TD align="left" nowrap width="200" bgcolor="WHITE">Wrooooooo!</TD>
117  * </tr>
118  * </table>
119  * </html:layer>
120  * </td>
121  * </tr>
122  * <tr>
123  * <td bgcolor="WHITE">
124  * <table border="0">
125  * <tr>
126  * <TD width="200" nowrap bgcolor="WHITE">question 2</TD>
127  * <TD align="left" nowrap width="200" bgcolor="WHITE">Wrooooooo!</TD>
128  * </tr>
129  * </table>
130  * </td>
131  * </tr>
132  * </table>
133  * </html:form>
134  * </body>
135  * </html:html>
136  */

137
138 /**
139  * Tag for input fields of type "LayerInput".
140  *
141  * @author Yves Henri AMAIZO
142  */

143 public class ExLayerInputTag extends ExLayerTag {
144
145     private String JavaDoc property = "";
146
147     private String JavaDoc value = "";
148
149     private List JavaDoc cascadedLayerControl = null;
150
151     private static String JavaDoc STR_JS_LAYER = "document.getElementById('%id%').style.display = '%action%';";
152
153
154     private static String JavaDoc SHOW = "block";
155
156     private static String JavaDoc HIDE = "none";
157
158
159     /**
160      * Constructor for ExLayerInputTag
161      */

162     public ExLayerInputTag() {
163         super();
164     }
165
166     public int doStartTag() throws JspException JavaDoc {
167         if (!property.equals("")) {
168             String JavaDoc defaultValue = "";
169             Input myInput = ControllerUtils.findInput(pageContext, property);
170             if (myInput == null) {
171                 throw new JspException JavaDoc("L'Input " + property + " n'est pas dans la response ");
172             } else {
173                 defaultValue = myInput.getDefaultValue();
174                 if (defaultValue.equals(value)) {
175                     setState("SHOW");
176                 } else {
177                     setState("HIDE");
178                 }
179             }
180         }
181         return super.doStartTag();
182     }
183
184     /**
185      * Standard doEndTag.
186      *
187      * @return int
188      */

189     public int doEndTag() throws JspException JavaDoc {
190         int retIntSuper = super.doEndTag();
191         String JavaDoc resultShow = "";
192         String JavaDoc resultHide = "";
193         String JavaDoc result = "";
194
195         resultShow += "function showLayer" + getId() + "(expand){\n";
196         resultHide += "function hideLayer" + getId() + "(expand){\n";
197
198         //List des comandes en cascade
199
if (cascadedLayerControl != null) {
200             Iterator JavaDoc itCascadeLayer = cascadedLayerControl.iterator();
201             boolean isCascadePresent = false;
202             if (itCascadeLayer.hasNext()) {
203                 resultShow += " if( expand == \"EXPAND\"){\n";
204                 resultHide += " if( expand == \"EXPAND\"){\n";
205                 isCascadePresent = true;
206             }
207             while (itCascadeLayer.hasNext()) {
208                 String JavaDoc idLayerControl = (String JavaDoc) itCascadeLayer.next();
209                 resultShow += " showLayer" + idLayerControl + "('EXPAND');\n";
210                 resultHide += " hideLayer" + idLayerControl + "('EXPAND');\n";
211             }
212             if (isCascadePresent) {
213                 resultShow += " }\n";
214                 resultHide += " }\n";
215             }
216
217         }
218
219         String JavaDoc jsShow = STR_JS_LAYER;
220         String JavaDoc jsHide = "";
221
222         jsShow = StringUtil.replaceString(jsShow, "%id%", getId());
223         jsHide = (jsShow);
224
225         String JavaDoc action = SHOW;
226         jsShow = StringUtil.replaceString(jsShow, "%action%", action);
227         action = HIDE;
228         jsHide = StringUtil.replaceString(jsHide, "%action%", action);
229
230         resultShow += " " + jsShow + "\n";
231         resultHide += " " + jsHide + "\n";
232         resultShow += "}";
233         resultHide += "}";
234
235         result += "\n<script language=\"JavaScript1.2\">\n";
236         result += resultShow + "\n";
237         result += resultHide + "\n";
238         result += "</script>\n";
239         ResponseUtils.write(pageContext, result);
240         return retIntSuper;
241     } /* doEndTag() */
242
243
244     /**
245      * Gets the property
246      *
247      * @return Returns a String
248      */

249     public String JavaDoc getProperty() {
250         return property;
251     }
252
253     /**
254      * Sets the property
255      *
256      * @param property The property to set
257      */

258     public void setProperty(String JavaDoc property) {
259         this.property = property;
260     }
261
262
263     /**
264      * Gets the value
265      *
266      * @return Returns a String
267      */

268     public String JavaDoc getValue() {
269         return value;
270     }
271
272     /**
273      * Sets the value
274      *
275      * @param value The value to set
276      */

277     public void setValue(String JavaDoc value) {
278         this.value = value;
279     }
280
281
282     /**
283      * Gets the value
284      *
285      * @param idLayer The id of layer to add on list
286      * @return Returns boolean false the not have been added
287      */

288     public boolean addLayerToHide(String JavaDoc idLayer) {
289         if (cascadedLayerControl == null) {
290             cascadedLayerControl = new Vector JavaDoc();
291         }
292         return cascadedLayerControl.add(idLayer);
293     }
294
295
296 }
297
298
Popular Tags