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.


Friday, April 2, 2010

no cache policy header, USE_APPLICATION_VIEW_CACHE not working properly

Problem : 
When I try to open a dialog box from my  page, I get the following error.


Apr 2, 2010 12:24:22 PM oracle.webcache.adf.config.AFCConfigFactory getConfig
INFO: ADF Config did not find the AFC config 
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.config.AFCConfigFactory getConfig
SEVERE: Error in config : Cannot locate config file. Using default values
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.config.AFCConfigFactory getConfig
SEVERE: Error in config. Using default values
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.filter.PageCachingProcessor getResponseFromCache
INFO: page (__ADFv__) cache miss
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.filter.PageCachingProcessor isResponseCacheable
INFO: response not cacheable - no cache policy header
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.filter.PageCachingProcessor getResponseFromCache
INFO: page (PPAPListDialog.jspx) cache miss
Apr 2, 2010 12:24:22 PM aam.tooling.managedbeans.LoggedUserInfo
INFO: In Logged User Info Bean...
Apr 2, 2010 12:24:22 PM oracle.webcache.adf.filter.PageCachingProcessor isResponseCacheable
INFO: response not cacheable - no cache policy header


Due to this error, the following things happen.

  • I keep on getting the Row Currency Error on navigating time and again to my dialog pages.
  • I have an attachment dialog with command link to save the attachment on user's system. It often refers to the firstly clicked attachment always even when I have clicked on the different link this time.
  • It does not update the dialog view properly. Sometimes newly added rows do not get displayed there.

Solution :
After a long study it was clear that it has something to do with the cache. But I just wondered where. Finally it was  USE_APPLICATION_VIEW_CACHE in the web.xml file. I set it to false and all the above mentioned errors went.
    <context-param>
        <param-name>oracle.adf.view.faces.USE_APPLICATION_VIEW_CACHE</param-name>
        <param-value>false</param-value>
    </context-param>
Although more information about USE_APPLICATION_VIEW_CACHE  can be found here but there is no reference that I could make why this be causing problem in my application. But still if you face the same problem (probably when it's a day before the UAT as in my case), you can give a thought to apply this solution.