1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 package com.ivata.mask.web.tag.util;
66
67
68 import java.util.Collection;
69
70 import javax.servlet.jsp.JspException;
71 import javax.servlet.jsp.PageContext;
72 import javax.servlet.jsp.tagext.TagSupport;
73
74
75 /***
76 * <p>This class is a wrapper tag to <code>Collection.add</code>.</p>
77 *
78 * <p><b>Tag attributes:</b><br/>
79 * <table cellpadding='2' cellspacing='5' border='0' align='center'
80 * width='85%'>
81 * <tr class='TableHeadingColor'>
82 * <th>attribute</th>
83 * <th>reqd.</th>
84 * <th>param. class</th>
85 * <th width='100%'>description</th>
86 * </tr>
87 * <tr class='TableRowColor'>
88 * <td>name</td>
89 * <td>true</td>
90 * <td><code>String</code></td>
91 * <td>The name of the <code>Collection</code> you .want
92 * to add an element to. This should have been instantiated with
93 * page scope using the <code>useBean</code> tag.</td>
94 * </tr>
95 * <tr class='TableRowColor'>
96 * <td>value</td>
97 * <td>true</td>
98 * <td><code>Object</code></td>
99 * <td>The value of the object you want to add.</td>
100 * </tr>
101 * </table>
102 * </p>
103 *
104 * @since ivata masks 0.5 (2002-06-29)
105 * @author Colin MacLeod
106 * <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
107 * @version $Revision: 1.2 $
108 */
109 public class CollectionAddTag extends TagSupport {
110
111 /***
112 * <p>Stores the name of the colleciton to add a new value to.</p>
113 */
114 private String name;
115
116 /***
117 * <p>Stores the value of the object to be added to the
118 * <code>Colleciton</code>.</p>
119 */
120 private Object value;
121
122 /***
123 * <p>Default constructor.</p>
124
125 */
126 public CollectionAddTag() {
127 super();
128 }
129
130 /***
131 * <p>Performs the action of adding the value supplied to the
132 * <code>Collection</code>.</p>
133 *
134 * <p>This method is called when the JSP engine encounters the start tag,
135 * after the attributes are processed.<p>
136 *
137 * <p>Scripting variables (if any) have their values set here.</p>
138 *
139 * @exception JspException if the <code>Collection</code> with
140 * the name specified does not exist at page scope.
141 * @return <code>SKIP_BODY</code> since this tag has no body.
142 */
143 public int doStartTag() throws JspException {
144
145 Collection collection = (Collection)
146 pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
147
148
149 if (collection == null) {
150 collection = (Collection) pageContext.getAttribute(name,
151 PageContext.SESSION_SCOPE);
152 }
153
154 if (collection == null) {
155 throw new JspException("Error in CollectionAddTag: No collection "
156 + "found in page or session scope called '"
157 + name
158 + "'");
159 }
160 collection.add(value);
161 return SKIP_BODY;
162 }
163
164 /***
165 * <p>Get the name of the collection to add a new value to.</p>
166 *
167 * @return the current value of the <code>Collection</code> name.
168 */
169 public final String getName() {
170 return name;
171 }
172
173 /***
174 * <p>Get the value of the object to be added to the
175 * <code>Colleciton</code>.</p>
176 *
177 * @return the current value of the object to be added.
178 */
179 public final Object getValue() {
180 return value;
181 }
182
183 /***
184 * <p>Set the name of the colleciton to add a new value to.</p>
185 *
186 * @param nameParam the new value of the <code>Collection</code> name.
187 */
188 public final void setName(final String nameParam) {
189 this.name = nameParam;
190 }
191
192 /***
193 * <p>Set the value of the object to be added to the
194 * <code>Colleciton</code>.</p>
195 *
196 * @param valueParam the new value of object to be added.
197 */
198 public final void setValue(final Object valueParam) {
199 this.value = valueParam;
200 }
201 }