You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by to...@apache.org on 2006/11/07 14:13:19 UTC
svn commit: r472097 -
/myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
Author: tomsp
Date: Tue Nov 7 05:13:19 2006
New Revision: 472097
URL: http://svn.apache.org/viewvc?view=rev&rev=472097
Log:
MYFACES-1419 reverted
Modified:
myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
Modified: myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java?view=diff&rev=472097&r1=472096&r2=472097
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/convert/BigDecimalConverter.java Tue Nov 7 05:13:19 2006
@@ -15,6 +15,8 @@
*/
package javax.faces.convert;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
import java.math.BigDecimal;
/**
@@ -23,21 +25,67 @@
* @author Thomas Spiegl (latest modification by $Author$)
* @version $Revision$ $Date$
*/
-public class BigDecimalConverter extends AbstractConverter {
- private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.BigDecimalConverter.CONVERSION";
+public class BigDecimalConverter
+ implements Converter
+{
+ private static final String CONVERSION_MESSAGE_ID = "javax.faces.convert.BigDecimalConverter.CONVERSION";
- public static final String CONVERTER_ID = "javax.faces.BigDecimal";
+ // FIELDS
+ public static final String CONVERTER_ID = "javax.faces.BigDecimal";
- // Methods implementation
- protected Object getAsObject(String value) {
- return new BigDecimal(value);
- }
-
- protected String getAsString(Object value) {
- return ((BigDecimal) value).toString();
- }
-
- protected String getConversionMessageId() {
- return CONVERSION_MESSAGE_ID;
- }
+ // CONSTRUCTORS
+ public BigDecimalConverter()
+ {
+ }
+
+ // METHODS
+ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String value)
+ {
+ if (facesContext == null) throw new NullPointerException("facesContext");
+ if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+ if (value != null)
+ {
+ {
+ value = value.trim();
+ if (value.length() > 0)
+ {
+ try
+ {
+ return new BigDecimal(value.trim());
+ }
+ catch (NumberFormatException e)
+ {
+ throw new ConverterException(_MessageUtils.getErrorMessage(facesContext,
+ CONVERSION_MESSAGE_ID,
+ new Object[]{uiComponent.getId(),value}), e);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value)
+ {
+ if (facesContext == null) throw new NullPointerException("facesContext");
+ if (uiComponent == null) throw new NullPointerException("uiComponent");
+
+ if (value == null)
+ {
+ return "";
+ }
+ if (value instanceof String)
+ {
+ return (String)value;
+ }
+ try
+ {
+ return ((BigDecimal)value).toString();
+ }
+ catch (Exception e)
+ {
+ throw new ConverterException(e);
+ }
+ }
}