Thursday, April 29, 2010

Client side Error Handling with validateRegExp on Decimal fields

There are undoubtedly more than one ways of handling the errors gracefully for your ADF inputText component. One of which is at the Model Layer using Validation at the Entity Objects the details of which can be seen here.
However, in some of the cases where we have an editable table dropped on the page and we need to provide the validation on all its fields, some of which are decimals, the various ways would be to use the various validators and converters as described here. However, this post describes 2 ways to handle the errors on the Decimal fields.

Note : To demonstrate the use of Decimal fields I've created a column Weight in the Employees table. Further I've created an Employees Entity Object, View Object and Application Module.

I also created a jspx page to Create/Update an Employee

Using the Validate Double Range :
Drag the validateDoubleRange validator from the Component Pallette under the JSF Core Menu and rop it under the inputText component. Remove ConvertNumber if any present. Just specify the range here as shown below.

At run time whenever an error occurs it shows the result in the following format.

However, the limitations of using this approach are :

  • You can not customize the message.
  • The Error messages are displayed after Submitting the page which involves a server call.

 Many times customers want client side validation messages in JavaScript alert boxes. The second approach demonstrates the same.

Using validateRegExp :
Validate Regular expression is a very efficient means to check for any format of the STRINGS. But unfortunately it can not be used for Numerical or Decimal data types. Even if you try to drop a validateRegExp validator under inputText, it works properly in case of errors but in case of correct value it throws an exception.

500 Internal Server Error
java.lang.IllegalArgumentException: 'value' is not of type java.lang.String. at oracle.adf.view.faces.validator.ValidatorUtils.assertIsString( at oracle.adf.view.faces.validator.RegExpValidator.validate( at oracle.adf.view.faces.component.UIXEditableValue.validateValue( at oracle.adf.view.faces.component.UIXEditableValue.validate( at oracle.adf.view.faces.component.UIXEditableValue._executeValidate( at oracle.adf.view.faces.component.UIXEditableValue.processValidators( at oracle.adf.view.faces.component.ChildLoop$Validate.process( at oracle.adf.view.faces.component.ChildLoop.runAlways( at oracle.adf.view.faces.component.ChildLoop.runAlways( at oracle.adf.view.faces.component.UIXColumn.processValidators( at oracle.adf.view.faces.component.UIXCollection.processComponent( at oracle.adf.view.faces.component.TableUtils$3.process( at ...

To remove this error, just change the data type of your attribute to String in the Entity Object as shown under. Please note the same Entity Object can be used for other View Objects also. Hence make sure that all the View Objects are in tact.

So everything is set. Just run the page now and see the output.

No comments:

Post a Comment