KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > CollectionSelector


1 /*
2   Copyright (C) 2003 Laurent Martelli <laurent@aopsys.com>
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui.web;
20
21 import java.io.PrintWriter JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Vector JavaDoc;
24 import org.objectweb.jac.core.NameRepository;
25
26 /**
27  * Selects objects from a collection with check boxes
28  */

29 public class CollectionSelector extends AbstractView
30     implements JacRequestReader
31 {
32     Vector JavaDoc selection = new Vector JavaDoc();
33     /**
34      * @param name the name for generated HTML <input> elements
35      */

36     public CollectionSelector(String JavaDoc name) {
37         this.label = name;
38     }
39
40     NameRepository nameRepository = (NameRepository)NameRepository.get();
41
42     /**
43      * Generate a checkbox for an item of the collection
44      */

45     public void genHTML(PrintWriter JavaDoc out, Object JavaDoc object) {
46         out.print("<input type=\"checkbox\" name=\""+label+"\" "+
47                   "value=\""+nameRepository.getName(object)+"\"");
48         printAttributes(out);
49         out.println(">");
50     }
51
52     public void readValue(JacRequest request) {
53         selection.clear();
54         String JavaDoc[] names = (String JavaDoc[])request.getParameters(label);
55         if (names!=null) {
56             for (int i=0; i<names.length; i++) {
57                 selection.add(nameRepository.getObject(names[i]));
58             }
59         }
60     }
61
62     public List getSelection() {
63         return selection;
64     }
65 }
66
67
Popular Tags