On 5/5/06, Mario Ivankovits <[EMAIL PROTECTED]> wrote:
What about a NumberConverter where you can add the wanted return type as
attribute.

Maybe.

The problem is that the return types have to be predefined in order to
insure there's no data loss.  For example:

   public Object getAsObject(FacesContext facesContext,
           UIComponent uiComponent, String value)
   {
       Number number = (Number)super.getAsObject(facesContext,
uiComponent, value);
       if (null == number)
       {
           return null;
       }

       if (number instanceof Double)
       {
           return new BigDecimal(number.doubleValue());
       }

       if (number instanceof Long)
       {
           return BigDecimal.valueOf(number.longValue());
       }

       throw new ConverterException("Expected number of type <Double>
or <Long> but received type <" + number.getClass().getName() + ">,
value <" + number.toString() + ">");
   }

I suppose I could also add in types for BigInteger, Byte, Double,
Float, Integer, Long, Short as well, but considering it'll make the
code much more complicated, I'm not sure if it's worthwhile if no one
else out there cares.

I think there's an need when working with currency data to keep things
as a BigDecimal -- I don't know how popular the other formats are
(Integer and BigInteger might be worth supporting).

Reply via email to