Showing posts with label Validations. Show all posts
Showing posts with label Validations. Show all posts

Sunday, November 28, 2010

Validating incoming String of Date format using Regular Expression

I was recently trying to restrict the format of the incoming variable so as to adhere it to the date format like 27-Nov-2010 04:17:37 PM. Well, this had to be pretty simple by using the xp20:matches function that can be used to match a string pattern against a regular expression. I used my function as

xp20:matches(bpws:getVariableData('inputVariable','payload','/ns3:PropertyDetails/ns3:PropertyValueToUpdate'), '^(0[1-9]|[12][0-9]|3[01])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[- /.](19|20)\d\d (0[1-9]|1[012])[:](0[1-9]|[12345][0-9])[:](0[1-9]|[12345][0-9]) (AM|PM)$')

Ooops. This was not working and but telling me Internal Xpath Error. Well the reason was that getVariableData() function gets the data from the XML schema element in Object format rather than in String. Finally, all I did was that I used the string() function to convert the object from variable data and it worked without any issue.

xp20:matches(string(bpws:getVariableData('inputVariable','payload','/ns3:PropertyDetails/ns3:PropertyValueToUpdate')), '^(0[1-9]|[12][0-9]|3[01])[- /.](Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[- /.](19|20)\d\d (0[1-9]|1[012])[:](0[1-9]|[12345][0-9])[:](0[1-9]|[12345][0-9]) (AM|PM)$')

Just a small learning…

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(ValidatorUtils.java:36) at oracle.adf.view.faces.validator.RegExpValidator.validate(RegExpValidator.java:103) at oracle.adf.view.faces.component.UIXEditableValue.validateValue(UIXEditableValue.java:378) at oracle.adf.view.faces.component.UIXEditableValue.validate(UIXEditableValue.java:206) at oracle.adf.view.faces.component.UIXEditableValue._executeValidate(UIXEditableValue.java:522) at oracle.adf.view.faces.component.UIXEditableValue.processValidators(UIXEditableValue.java:302) at oracle.adf.view.faces.component.ChildLoop$Validate.process(ChildLoop.java:67) at oracle.adf.view.faces.component.ChildLoop.runAlways(ChildLoop.java:39) at oracle.adf.view.faces.component.ChildLoop.runAlways(ChildLoop.java:30) at oracle.adf.view.faces.component.UIXColumn.processValidators(UIXColumn.java:70) at oracle.adf.view.faces.component.UIXCollection.processComponent(UIXCollection.java:822) at oracle.adf.view.faces.component.TableUtils$3.process(TableUtils.java:256) 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.