KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > servlet > http > jsp > tagext > HiddenObjectTag


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.servlet.http.jsp.tagext;
8
9 import javax.servlet.jsp.JspException JavaDoc;
10 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
11
12 import org.apache.struts.util.RequestUtils;
13 import org.apache.struts.util.ResponseUtils;
14
15 /**
16  * Tag that generates an HTML hidden input field
17  * <p>
18  * The field is created with :<ul>
19  * <li>The <code>id</code> parameter : used as the name</li>
20  * <li>The <code>name</code>,<code>property</code> and <code>scope</code> parameter : used to fetch an object. This object is then used as the value</li>
21  * </ul>
22  * </p>
23  *
24  * @author Laurent Etiemble
25  * @version $Revision: 1.4 $
26  * @jsp:tag name="hidden"
27  * body-content="empty"
28  */

29 public class HiddenObjectTag extends TagSupport JavaDoc
30 {
31    /** Id property of the tag */
32    protected String JavaDoc id = null;
33    /** Name property of the tag */
34    protected String JavaDoc name = null;
35    /** Property property of the tag */
36    protected String JavaDoc property = null;
37    /** Scope property of the tag */
38    protected String JavaDoc scope = null;
39
40
41    /**
42     * Executed when the start tag is encountered
43     *
44     * @return An int value to resume or not the processing
45     * @exception JspException In case of problem
46     */

47    public int doStartTag()
48       throws JspException JavaDoc
49    {
50       Object JavaDoc object = null;
51
52       // Look up the requested bean (if necessary)
53
if (property != null)
54       {
55          object = RequestUtils.lookup(pageContext, this.name, this.property, this.scope);
56       }
57       else
58       {
59          object = RequestUtils.lookup(pageContext, this.name, this.scope);
60       }
61
62       if (object == null)
63       {
64          throw new JspException JavaDoc("Unable to find bean " + this.name + " or its property " + this.property);
65       }
66
67       // Output the field
68
StringBuffer JavaDoc output = new StringBuffer JavaDoc();
69       output.append("<input type=\"hidden\" name=\"");
70       output.append(this.id);
71       output.append("\" value=\"");
72       output.append(ResponseUtils.filter(object.toString()));
73       output.append("\"/>");
74
75       ResponseUtils.write(pageContext, output.toString());
76
77       // Continue processing this page
78
return (SKIP_BODY);
79    }
80
81
82    /**
83     * Gets the id value of this tag
84     *
85     * @return The id value
86     * @jsp:attribute name="id"
87     * required="true"
88     * rtexprvalue="true"
89     */

90    public String JavaDoc getId()
91    {
92       return this.id;
93    }
94
95
96    /**
97     * Gets the name value of this tag
98     *
99     * @return The name value
100     * @jsp:attribute name="name"
101     * required="true"
102     * rtexprvalue="true"
103     */

104    public String JavaDoc getName()
105    {
106       return this.name;
107    }
108
109
110    /**
111     * Gets the property value of this tag
112     *
113     * @return The property value
114     * @jsp:attribute name="property"
115     * required="false"
116     * rtexprvalue="true"
117     */

118    public String JavaDoc getProperty()
119    {
120       return this.property;
121    }
122
123
124    /**
125     * Gets the scope value of this tag
126     *
127     * @return The scope value
128     * @jsp:attribute name="scope"
129     * required="false"
130     * rtexprvalue="true"
131     */

132    public String JavaDoc getScope()
133    {
134       return this.scope;
135    }
136
137
138    /** Release all allocated resources. */
139    public void release()
140    {
141       super.release();
142       this.id = null;
143       this.name = null;
144       this.property = null;
145       this.scope = null;
146    }
147
148
149    /**
150     * Sets the id value of this tag
151     *
152     * @param id The new id value
153     */

154    public void setId(String JavaDoc id)
155    {
156       this.id = id;
157    }
158
159
160    /**
161     * Sets the name value of this tag
162     *
163     * @param name The new name value
164     */

165    public void setName(String JavaDoc name)
166    {
167       this.name = name;
168    }
169
170
171    /**
172     * Sets the property value of this tag
173     *
174     * @param property The new property value
175     */

176    public void setProperty(String JavaDoc property)
177    {
178       this.property = property;
179    }
180
181
182    /**
183     * Sets the scope value of this tag
184     *
185     * @param scope The new scope value
186     */

187    public void setScope(String JavaDoc scope)
188    {
189       this.scope = scope;
190    }
191 }
192
193
Popular Tags