cancel
Showing results for 
Search instead for 
Did you mean: 

Validating BigDecimal

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182294
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Thanks Abhilash, your solution is simple and worked out very well.

Answers (2)

Answers (2)

Former Member
0 Kudos

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;

Former Member
0 Kudos

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/BigIntegerValida...

Regards,

Vito