Skip to Content
avatar image
Former Member

Validating BigDecimal

Hello,

I am using an Input field of Big Decimal type. If the user enters characters or anything other, I need to show error image.

Could you please tell, how to validate the bigdecimal?. Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 27, 2007 at 04:16 PM

    How you are assigning BigDecimal to InputField? I guess your context attribute is of type string but you want to validate to accept only BigDecimal.

    There is no direct InputAction so you should validate on any of the button action:

    String bigValue = wdContext.currentContextElement().getBigDecValue();

    boolean validValue = true;

    BigDecimal bigObj = null;

    try

    {

    bigObj = new BigDecimal(bigValue);

    }

    catch(NumberFormatException nfe)

    {

    validValue = false;

    wdComponentAPI.getMessageManager().reportException("Invalid value",false);

    }

    if(validValue)

    {

    //continue ur logic

    }

    Regards

    AG

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 28, 2007 at 01:26 AM

    Hi,

    I've a function to get big decimal for your reference.

    You can do this in a try/catch block to display in case of error.

    Hope it helps.

    yung siu wai

    public java.math.BigDecimal getBigDecimalValue( java.lang.Object object )

    {

    //@@begin getBigDecimalValue()

    if (object instanceof String){

    return new BigDecimal((String)object);

    } else if (object instanceof Integer){

    return new BigDecimal(((Integer)object).doubleValue());

    } else if (object instanceof BigDecimal){

    return new BigDecimal(((BigDecimal)object).doubleValue());

    } else return null;

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 27, 2007 at 04:17 PM

    Hi Sunita,

    I never try it, but probabily it may help you, using isValid() function:

    http://commons.apache.org/validator/api-1.3.1/org/apache/commons/validator/routines/BigIntegerValidator.html

    Regards,

    Vito

    Add comment
    10|10000 characters needed characters exceeded