Friday, December 21, 2012

Skip Validation for ADF Required Tabs

Tell me - how often it happend to implement such basic layout where required attributes from one Entity are located on the same fragment/page but in different tabs? I guess quite often, this is common requirement. However, is not so obvious how to implement it properly. Most likely you will end up into infinite loop of validation errors for required fields when trying to switch between tabs. I will describe in this post how to implement multiple tabs with required attributes from the same Entity and avoid unexpected validation errors.

Sample application - TestValidationApp.zip is based on Employees EO and contains two tabs - Contact and Details. Half of Employees attributes are located under Contact and the rest under Details tab:


Firstly I will show you how it works by default. Press Create button, this will call CreateInsert operation and insert new row (attributes from this row will be initialized blank in both tabs):


Type values for required fields and try to open second tab - Details. Validation errors are displayed for missing attribute values in the second tab. But wait a bit - we want to open Details tab and already getting validation errors? This makes our form unusable:


Let's make first attempt to solve this problem - set Immediate = true for both tabs. In theory this should help, in practice it doesn't. Immediate = true allows to skip validation lifecycle, but as a side effect it prevents Model update and value is not set.  Immediate = true will not solve described issue, but still let's test it - I will show you why Immediate = true doesn't help at all. Select both tabs in JDeveloper:


Set Immediate = true property for both tabs:


Do the same test again - create new record and type required values in the first tab:


Because of Immediate = true - we can open second tab without getting validation errors. Type required values in the second tab and press Save. Validation errors are reported for the required values in the first tab. This is quite a magic, actually not - this happens because of Immediate = true - entered data is not stored on the Model:


Set Immediate = true to be false for both tabs, as it was originally:


Solution will be described now. Open page definition file and select root tag in the structure window:


Go to Properties window and search for SkipValidation property. Set SkipValidation to true:


This allows to prevent such silly validation execution as you saw above. Enter required values in the first tab:


Switch to the second tab - enter required values there. Press Save button to commit transaction - no errors this time:


SkipValidation = true doesn't affect regular ADF validation behavior - if required field value is missing during transaction commit - ADF will stop processing and ask user to provide a values as expected:

6 comments:

ojk said...

Is there any way to skip required fields validation when switching between tabs and perform it only on submit?

Andrejus Baranovskis said...

Its what this post about. Isnt it?

Andrejus

ojk said...

I meant: switch to the second tab without entering required values in the firs tab :).

Andrejus Baranovskis said...

This is what I describe in this post: "Because of Immediate = true - we can open second tab without getting validation errors"

Andrejus

JoseAróstegui said...

Hi Andrejus,

Don't know what I'm doing wrong but I still get the not null validation messages. I've:

1) Downloaded the zip sample

2) Changed "SkipValidation" to both emplsViewPageDef and mainPageDef

3) Both Contact and Details showDetailItem have Immediate property to false.

Thanks a lot in advance.
Jose.

Andrejus Baranovskis said...

There is no need to change anything - skipValidation = true is already set on Employees fragment.

This sample was implemented with ADF 11g R2, which ADF version are you using?

Andrejus