1 /*******************************************************************************
2 * Imixs Workflow
3 * Copyright (C) 2001, 2011 Imixs Software Solutions GmbH,
4 * http://www.imixs.com
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You can receive a copy of the GNU General Public
17 * License at http://www.gnu.org/licenses/gpl.html
18 *
19 * Project:
20 * http://www.imixs.org
21 * http://java.net/projects/imixs-workflow
22 *
23 * Contributors:
24 * Imixs Software Solutions GmbH - initial API and implementation
25 * Ralph Soika - Software Developer
26 *******************************************************************************/
27
28 package org.imixs.workflow.jee.faces;
29
30 import java.util.ListIterator;
31 import java.util.Vector;
32
33 import javax.faces.component.UIComponent;
34 import javax.faces.context.FacesContext;
35 import javax.faces.convert.Converter;
36 import javax.faces.convert.ConverterException;
37
38 /*
39 * für ConfigItem benutzter Converter, der einen Komma-separierten String in einen Vektor umwandelt
40 * und umgekehrt.
41 *
42 * Noch dringend zu tun:
43 * - Dem Converter im Fehlerfall noch eine eigene Fehlermeldung mitgeben
44 * - müssen da nicht noch eine Menge try-catch blöcke und Typ-Prüfungen rein?
45 * Derzeit geht das alles sehr optimistisch davon aus, dass in dem Vektor wirklich
46 * auch Strings drin sind; was eigentlich auch der Fall ist. Interessant wird es, wenn
47 * man bestehende Felder umbiegt.
48 *
49 * Schön wäre noch folgendes:
50 * - Den Separator im converter-tag der JSP Seite definieren. Das wird allerdings ein Act (Vorgehen
51 * beschrieben in Kap. 20.4 in "Kito Mann - JSF in Action")
52 */
53
54 public class VectorConverter implements Converter {
55
56 String separator = "\n";
57
58 public Object getAsObject(FacesContext context, UIComponent component,
59 String value) throws ConverterException {
60
61 Vector v = new Vector();
62 String[] tokens = value.split(separator);
63 for (int i = 0; i < tokens.length; i++) {
64 v.addElement(tokens[i].trim());
65 }
66
67 return v;
68
69 }
70
71 public String getAsString(FacesContext context, UIComponent component,
72 Object value) throws ConverterException {
73
74 String s = "";
75 Vector vValues = null;
76
77 if (value instanceof Vector)
78 vValues = (Vector) value;
79 else
80 vValues = new Vector();
81 ListIterator li = vValues.listIterator();
82 while (li.hasNext()) {
83 if (li.hasPrevious()) {
84 s += separator;
85 }
86 s += li.next();
87 }
88
89 return s;
90
91 }
92
93 }