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 * Das ist alles noch sehr basic und ich fürchte auch nicht sehr defensiv programmiert.
42 *
43 * Noch dringend zu tun:
44 * - Dem Converter im Fehlerfall noch eine eigene Fehlermeldung mitgeben
45 * - müssen da nicht noch eine Menge try-catch blöcke und Typ-Prüfungen rein?
46 * Derzeit geht das alles sehr optimistisch davon aus, dass in dem Vektor wirklich
47 * auch Strings drin sind; was eigentlich auch der Fall ist. Interessant wird es, wenn
48 * man bestehende Felder umbiegt.
49 *
50 * Schön wäre noch folgendes:
51 * - Den Separator im converter-tag der JSP Seite definieren. Das wird allerdings ein Act (Vorgehen
52 * beschrieben in Kap. 20.4 in "Kito Mann - JSF in Action")
53 */
54
55 public class VectorIntegerConverter implements Converter {
56
57 String separator = "\n";
58
59 public Object getAsObject(FacesContext context, UIComponent component,
60 String value) throws ConverterException {
61
62
63 Vector v = new Vector();
64 String[] tokens = value.split(separator);
65 for (int i = 0; i < tokens.length; i++) {
66 String sValue=tokens[i].trim();
67 Integer intValue=new Integer(sValue);
68 v.addElement(intValue);
69 }
70
71 return v;
72
73 }
74
75 public String getAsString(FacesContext context, UIComponent component,
76 Object value) throws ConverterException {
77
78 String s = "";
79 Vector vValues = (Vector)value;
80 ListIterator li = vValues.listIterator();
81 while(li.hasNext()){
82 if(li.hasPrevious()){
83 s += ""+separator;
84 }
85 s += li.next();
86 }
87
88 return s;
89
90 }
91
92 }