1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.examples.mailreaderjpa;
19
20 import javax.faces.component.UIComponent;
21 import javax.faces.context.FacesContext;
22 import javax.faces.convert.Converter;
23 import javax.faces.convert.ConverterException;
24 import org.apache.mailreaderjpa.Protocol;
25
26 /***
27 * <p>JSF <code>Converter</code> for mapping between a <code>Protocol</code>
28 * and its string representation.</p>
29 */
30 public class ProtocolConverter implements Converter {
31
32
33
34
35
36 /***
37 * <p>Return the string representation of the specified
38 * <code>Protocol</code> value.</p>
39 *
40 * @param context <code>FacesContext</code> for the current request
41 * @param component <code>UIComponent</code> whose value is being converted
42 * @param value {@link Protocol} being converted
43 *
44 * @exception ConverterException if a conversion error occurs
45 */
46 public String getAsString(FacesContext context, UIComponent component,
47 Object value) throws ConverterException {
48
49 Protocol protocol = (Protocol) value;
50 return "" + protocol.getId();
51
52 }
53
54
55 /***
56 * <p>Return the <code>Protocol</code> instance corresponding to the
57 * specified string representation.</p>
58 *
59 * @param context <code>FacesContext</code> for the current request
60 * @param component <code>UIComponent</code> whose value is being converted
61 * @param value String representation of the value
62 *
63 * @exception ConverterException if a conversion error occurs
64 */
65 public Object getAsObject(FacesContext context, UIComponent component,
66 String value) throws ConverterException {
67
68 Logic logic =
69 (Logic) context.getExternalContext().getApplicationMap().get("logic");
70 return logic.findProtocolById(Integer.valueOf(value).intValue());
71
72 }
73
74
75 }