1
2
3
4 package org.rcfaces.core.converter;
5
6 import javax.faces.component.UIComponent;
7 import javax.faces.context.FacesContext;
8 import javax.faces.convert.ConverterException;
9
10
11
12
13
14
15 public class FloatConverter extends AbstractNumberConverter {
16 private static final String REVISION = "$Revision: 1.1 $";
17
18 public FloatConverter() {
19 setIntegerOnly(false);
20 }
21
22 public Object getAsObject(FacesContext context, UIComponent component,
23 String value) {
24
25 if (value == null || value.trim().length() < 1) {
26 Object v = getDefaultValue();
27 if (v instanceof Float) {
28 return v;
29 }
30 if (v instanceof Number) {
31 return new Float(((Number) v).floatValue());
32 }
33 value = (String) v;
34 }
35
36 Number number = (Number) super.getAsObject(context, component, value);
37
38 if (number == null || (number instanceof Float)) {
39 return number;
40 }
41
42 double d = number.doubleValue();
43 if (d < Float.MIN_VALUE || d > Float.MAX_VALUE) {
44 throw new ConverterException(
45 "Number can not be converted to float. (value=" + d + ")");
46 }
47
48 return new Float(number.floatValue());
49 }
50 }