1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.convert; |
20 | |
|
21 | |
import javax.faces.component.UIComponent; |
22 | |
import javax.faces.context.FacesContext; |
23 | |
|
24 | |
import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFConverter; |
25 | |
|
26 | |
import java.math.BigInteger; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
@JSFConverter |
32 | |
public class BigIntegerConverter |
33 | |
implements Converter |
34 | |
{ |
35 | |
|
36 | |
public static final String CONVERTER_ID = "javax.faces.BigInteger"; |
37 | |
public static final String STRING_ID = "javax.faces.converter.STRING"; |
38 | |
public static final String BIGINTEGER_ID = "javax.faces.converter.BigIntegerConverter.BIGINTEGER"; |
39 | |
|
40 | |
|
41 | |
public BigIntegerConverter() |
42 | 0 | { |
43 | 0 | } |
44 | |
|
45 | |
|
46 | |
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) |
47 | |
{ |
48 | 0 | if (facesContext == null) |
49 | |
{ |
50 | 0 | throw new NullPointerException("facesContext"); |
51 | |
} |
52 | 0 | if (uiComponent == null) |
53 | |
{ |
54 | 0 | throw new NullPointerException("uiComponent"); |
55 | |
} |
56 | |
|
57 | 0 | if (value != null) |
58 | |
{ |
59 | 0 | value = value.trim(); |
60 | 0 | if (value.length() > 0) |
61 | |
{ |
62 | |
try |
63 | |
{ |
64 | 0 | return new BigInteger(value.trim()); |
65 | |
} |
66 | 0 | catch (NumberFormatException e) |
67 | |
{ |
68 | 0 | throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, |
69 | |
BIGINTEGER_ID, |
70 | |
new Object[]{value,"2345",_MessageUtils.getLabel(facesContext, uiComponent)}), e); |
71 | |
} |
72 | |
} |
73 | |
} |
74 | 0 | return null; |
75 | |
} |
76 | |
|
77 | |
public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) |
78 | |
{ |
79 | 0 | if (facesContext == null) |
80 | |
{ |
81 | 0 | throw new NullPointerException("facesContext"); |
82 | |
} |
83 | 0 | if (uiComponent == null) |
84 | |
{ |
85 | 0 | throw new NullPointerException("uiComponent"); |
86 | |
} |
87 | |
|
88 | 0 | if (value == null) |
89 | |
{ |
90 | 0 | return ""; |
91 | |
} |
92 | 0 | if (value instanceof String) |
93 | |
{ |
94 | 0 | return (String)value; |
95 | |
} |
96 | |
try |
97 | |
{ |
98 | 0 | return ((BigInteger)value).toString(); |
99 | |
} |
100 | 0 | catch (Exception e) |
101 | |
{ |
102 | 0 | throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, STRING_ID, |
103 | |
new Object[]{value,_MessageUtils.getLabel(facesContext, uiComponent)}),e); |
104 | |
} |
105 | |
} |
106 | |
|
107 | |
} |