1 16 package javax.faces.convert; 17 18 import javax.faces.component.UIComponent; 19 import javax.faces.context.FacesContext; 20 import java.math.BigDecimal ; 21 22 37 public class BigDecimalConverter 38 implements Converter 39 { 40 private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.BigDecimalConverter.CONVERSION"; 41 42 public static final String CONVERTER_ID = "javax.faces.BigDecimal"; 44 45 public BigDecimalConverter() 47 { 48 } 49 50 public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) 52 { 53 if (facesContext == null) throw new NullPointerException ("facesContext"); 54 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 55 56 if (value != null) 57 { 58 { 59 value = value.trim(); 60 if (value.length() > 0) 61 { 62 try 63 { 64 return new BigDecimal (value.trim()); 65 } 66 catch (NumberFormatException e) 67 { 68 throw new ConverterException(_MessageUtils.getErrorMessage(facesContext, 69 CONVERSION_MESSAGE_ID, 70 new Object []{uiComponent.getId(),value}), e); 71 } 72 } 73 } 74 } 75 return null; 76 } 77 78 public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) 79 { 80 if (facesContext == null) throw new NullPointerException ("facesContext"); 81 if (uiComponent == null) throw new NullPointerException ("uiComponent"); 82 83 if (value == null) 84 { 85 return ""; 86 } 87 if (value instanceof String ) 88 { 89 return (String )value; 90 } 91 try 92 { 93 return ((BigDecimal )value).toString(); 94 } 95 catch (Exception e) 96 { 97 throw new ConverterException(e); 98 } 99 } 100 } 101 | Popular Tags |