KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > jsptag > SelectGroupTag


1 /*
2  * SelectEPersonTag
3  *
4  * Version: $Revision: 1.1 $
5  *
6  * Date: $Date: 2005/10/13 05:48:03 $
7  *
8  * Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40
41 package org.dspace.app.webui.jsptag;
42
43 import java.io.IOException JavaDoc;
44
45 import javax.servlet.http.HttpServletRequest JavaDoc;
46 import javax.servlet.jsp.JspException JavaDoc;
47 import javax.servlet.jsp.JspWriter JavaDoc;
48 import javax.servlet.jsp.jstl.fmt.LocaleSupport;
49 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
50
51 import org.dspace.eperson.Group;
52
53 /**
54  * <P>Tag for producing an e-person select widget in a form. Somewhat
55  * analogous to the HTML SELECT element. An input
56  * field is produced with a button which pops up a window from which
57  * e-people can be selected. Selected e-epeople are added to the field
58  * in the form. If the selector is for multiple e-people, a 'remove
59  * selected from list' button is also added.</P>
60  *
61  * <P>On any form that has a selecteperson tag (only one allowed per page),
62  * you need to include the following Javascript code on all of the submit
63  * buttons, to ensure that the e-people IDs are posted and that the popup
64  * window is closed:</P>
65  *
66  * <P><code>onclick="javascript:finishEPerson();"</code></P>
67  *
68  * @author Robert Tansley
69  * @version $Revision: 1.1 $
70  */

71 public class SelectGroupTag extends TagSupport JavaDoc
72 {
73     /** Multiple groups? */
74     private boolean multiple;
75     
76     /** Which groups are initially in the list? */
77     private Group[] groups;
78
79
80     public SelectGroupTag()
81     {
82         super();
83     }
84
85     
86     /**
87      * Setter for multiple attribute
88      *
89      * @param s attribute from JSP
90      */

91     public void setMultiple(String JavaDoc s)
92     {
93         if (s != null && (s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("true")))
94         {
95             multiple = true;
96         }
97         else
98         {
99             multiple = false;
100         }
101     }
102
103     /**
104      * Setter for groups in list
105      *
106      * @param e attribute from JSP
107      */

108     public void setSelected(Object JavaDoc g)
109     {
110         if (g instanceof Group)
111         {
112             groups = new Group[1];
113             groups[0] = (Group) g;
114         }
115         else if(g instanceof Group[])
116         {
117             groups = (Group[]) g;
118         }
119     }
120
121     
122     public void release()
123     {
124         multiple = false;
125         groups = null;
126     }
127
128
129     public int doStartTag()
130         throws JspException JavaDoc
131     {
132         try
133         {
134             JspWriter JavaDoc out = pageContext.getOut();
135             HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc) pageContext.getRequest();
136             
137             out.print("<table><tr><td colspan=\"2\" align=\"center\"><select multiple=\"multiple\" name=\"group_ids\" size=\"");
138             out.print(multiple ? "10" : "1");
139             out.println("\">");
140             
141             //ensure that if no group is selected that a blank option is displayed - xhtml compliance
142
if (groups == null || groups.length == 0)
143             {
144               out.print("<option value=\"\">&nbsp;</option>");
145             }
146             
147             if (groups != null)
148             {
149                 for (int i = 0; i < groups.length; i++)
150                 {
151                     out.print("<option value=\"" + groups[i].getID() + "\">");
152                     out.print(groups[i].getName() + " (" + groups[i].getID() + ")");
153                     out.println("</option>");
154                 }
155             }
156             
157             out.print("</select></td>");
158             
159             if (multiple)
160             {
161                 out.print("</tr><tr><td width=\"50%\" align=\"center\">");
162             }
163             else
164             {
165                 out.print("<td>");
166             }
167             
168             String JavaDoc p = (multiple ?
169                     LocaleSupport.getLocalizedMessage(pageContext,
170                             "org.dspace.app.webui.jsptag.SelectGroupTag.selectGroups")
171                     : LocaleSupport.getLocalizedMessage(pageContext,
172                             "org.dspace.app.webui.jsptag.SelectGroupTag.selectGroup") );
173             out.print("<input type=\"button\" value=\"" + p
174                             + "\" onclick=\"javascript:popup_window('"
175                             + req.getContextPath() + "/tools/group-select-list?multiple="
176                             + multiple + "', 'group_popup');\" />");
177             
178             if (multiple)
179             {
180                 out.print("</td><td width=\"50%\" align=\"center\">");
181                 out.print("<input type=\"button\" value=\""
182                             + LocaleSupport.getLocalizedMessage(pageContext,
183                                 "org.dspace.app.webui.jsptag.SelectGroupTag.removeSelected")
184                                 + "\" onclick=\"javascript:removeSelected(window.document.forms[0].group_ids);\"/>");
185             }
186
187             out.println("</td></tr></table>");
188         }
189         catch (IOException JavaDoc ie)
190         {
191             throw new JspException JavaDoc(ie);
192         }
193         
194         return SKIP_BODY;
195     }
196 }
197
Popular Tags