KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > panel > HideTag


1 /**
2  * May 1, 2006
3  *
4  * Copyright 2004 uitags
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.sf.uitags.tag.panel;
19
20 import javax.servlet.jsp.JspException JavaDoc;
21
22 import net.sf.uitags.tag.AbstractUiTag;
23 import net.sf.uitags.tagutil.TaglibProperties;
24 import net.sf.uitags.tagutil.validation.RuntimeValidator;
25 import net.sf.uitags.util.StringUtils;
26 import net.sf.uitags.util.Template;
27
28 /**
29  * Injects panel hide capability in response to a certain event.
30  *
31  * @author hgani
32  * @version $Id$
33  */

34 public class HideTag extends AbstractUiTag {
35
36   ///////////////////////////////
37
////////// Constants //////////
38
///////////////////////////////
39

40   /**
41    * Serial Version UID.
42    */

43   private static final long serialVersionUID = 100L;
44
45   
46   ///////////////////////////////////////////////
47
////////// Property keys (constants) //////////
48
///////////////////////////////////////////////
49

50   private static final String JavaDoc PROP_EVENT = "panel.hide.on";
51   private static final String JavaDoc PROP_DELAY = "panel.hide.delay";
52   private static final String JavaDoc PROP_FORCE = "panel.hide.force";
53
54
55   ////////////////////////////
56
////////// Fields //////////
57
////////////////////////////
58

59   /**
60    * The 'injectTo' tag attribute.
61    */

62   private String JavaDoc injectTo;
63
64   /**
65    * The 'injectToName' tag attribute.
66    */

67   private String JavaDoc injectToName;
68
69   /**
70    * The "on" tag attribute
71    */

72   private String JavaDoc on;
73
74   /**
75    * The "delay" tag attribute
76    */

77   private Integer JavaDoc delayInMillis;
78
79   /**
80    * The "force" tag attribute
81    */

82   private Boolean JavaDoc force;
83
84
85   ///////////////////////////////////////////
86
////////// Tag attribute setters //////////
87
///////////////////////////////////////////
88

89   /**
90    * Tag attribute setter.
91    *
92    * @param val value of the tag attribute
93    */

94   public void setInjectTo(String JavaDoc val) {
95     this.injectTo = val;
96   }
97
98   /**
99    * Tag attribute setter.
100    *
101    * @param val value of the tag attribute
102    */

103   public void setInjectToName(String JavaDoc val) {
104     this.injectToName = val;
105   }
106
107   /**
108    * Tag attribute setter.
109    *
110    * @param val value of the tag attribute
111    */

112   public void setOn(String JavaDoc val) {
113     this.on = val;
114   }
115
116   /**
117    * Tag attribute setter.
118    *
119    * @param val value of the tag attribute
120    */

121   public void setDelay(Integer JavaDoc val) {
122     this.delayInMillis = val;
123   }
124
125   /**
126    * Tag attribute setter.
127    *
128    * @param val value of the tag attribute
129    */

130   public void setForce(Boolean JavaDoc force) {
131     this.force = force;
132   }
133
134
135   ///////////////////////////////
136
////////// Tag logic //////////
137
///////////////////////////////
138

139   /**
140    * Instructs web container to skip the tag's body.
141    *
142    * @see javax.servlet.jsp.tagext.Tag#doStartTag()
143    * @return <code>SKIP_BODY</code>
144    * @throws JspException to communicate error
145    */

146   public int doStartTag() throws JspException JavaDoc {
147     return SKIP_BODY;
148   }
149
150   /**
151    * Renders the HTML code for hiding a panel.
152    *
153    * @see javax.servlet.jsp.tagext.Tag#doEndTag()
154    * @return <code>EVAL_PAGE</code>
155    * @throws JspException to communicate error
156    */

157   public int doEndTag() throws JspException JavaDoc {
158     RuntimeValidator.assertAttributeExclusive(
159         "injectTo", this.injectTo, "injectToName", this.injectToName);
160     RuntimeValidator.assertEitherSpecified(
161         "injectTo", this.injectTo, "injectToName", this.injectToName);
162
163     TaglibProperties props = TaglibProperties.getInstance();
164     props.setRuntimeProperty(PROP_EVENT, this.on);
165     props.setRuntimeProperty(PROP_DELAY, StringUtils.toStringOrNull(this.delayInMillis));
166     props.setRuntimeProperty(PROP_FORCE, StringUtils.toStringOrNull(this.force));
167
168     Template tpl = Template.forName(Template.PANEL_HIDE);
169     tpl.map("triggerId", this.injectTo);
170     tpl.map("triggerName", this.injectToName);
171     tpl.map("triggerEvent", props.get(PROP_EVENT));
172     tpl.map("delayInMillis", Integer.valueOf(props.get(PROP_DELAY)));
173     tpl.map("force", Boolean.valueOf(props.get(PROP_FORCE)));
174
175     PanelTag parent = (PanelTag) findParent(PanelTag.class);
176     parent.addChildJsCode(tpl.evalToString());
177
178     return EVAL_PAGE;
179   }
180 }
181
Popular Tags