Wednesday, 13 August 2014

overview of skipValidation attribute

ADF as a technology allows you to achieve a lot of things in many many ways. That refers mostly to the validation process. One of them needs few days of coding, other are simple. But, as usually, you need to know that they exists. Let's assume a common business case - the bigger form has been divided to several smaller parts. There are both single attribute and whole entity validators defined. For instance, you are not able to have a mortgage without a collateral, or an insurance policy without policyholder. Each entity has its own attributes which are at least mandatory. There are also cross entity dependencies. Such cases sounds so simple but on the other hand could take a lot of effort to develope. Please think how to implement such case.

To simplify the real life scenarios, Employees entity from HR schema will be fulfilled in three steps wizard. On the first station user is supposed to fill first name, last name and the e-mail address. On the second one there will be placed the rest of the attributes. On the third one, there will be only a read only summary. Please create a demo fusion application. In the model project please create only Employees entity and an updateable ViewObject based on it using Business Components from Tables option.

Now please create new taskflow, drop three view activities and connect them as on the picture below. Create each page by double click on the activity.

Drag EmployeesView from the Data Control and drop on the first page. Select only FirstName, LastName and Email attributes. Please drag and drop Commit (from the root node of AppModuleDataControl) and CreateInsert (the EmployeesView1 node in the AppModuleDataControl) operations and add buttons to call navigation actions.

Do the same for the second view but pick all attributes excluding three mentioned before.

Note that on each two pages few of the attributes are mandatory. On the last page drag EmployeesView as read-only form.

Commit button should be always enabled (for tests purposes). Create an empty JSP page and drop the taskflow on it. The page is ready for testing so please run the sample. During the test please click CreateInsert button to create new row and Next button to navigate to the second page. Validation error has been thrown.

Behavior is expected, on the form there are required mandatory fields. The form contains mandatory attributes which needs to be fulfilled. Please put test data into them and one more time click Next.

Another error! About the fields that aren't currently displayed. First thing ever done on such error is to set Immediate attribute of command buttons to true. It is worth to try, so please set Immediate="true" for Next button on the first page and try the test again. Put test values into LastName and Email, press Next and fulfill each mandatory field on the second page. After that please click Commit.

One more time an error! And it is about the fields that shouldn't be empty. Should they? In fact they should be empty. The reason is hidden in the Immediate attribute. The deeper look inside the JSF life cycle will give the answer.

(image source:

After set immediate to true the Update Model Values phase is omitted. Even if you have typed values in the browser, the BC4J layer is not updated with them. The question now is what to do else. One of possible solution is to set autoSubmit to true for each mandatory field. Or remove mandatory at the entity level, the database will check it on its side. Not really good thinking, it'll cause a lot of AJAX calls in the background, what with the application performance? There is at least 3-tier architecture... What if the validation will be much more sophisticated?

Please revert the immediate changes, autoSubmit and mandatory settings if you've tried it. Now please go to the page definition of the first and the second page. In the Structure window select root node, in the Property Inspector change skipValidation attribute to true and run the tests again.

It is impossible to click Next on the first page while there is at least one mandatory attribute. But after filling them you can go to the second page to work there. You can easily go back to the first one or try to Commit changes.

SkipValidation attribute bypasses the model entity validations to the transaction's commit. Mandatory checks are fired, that's why such attributes cannot be empty. One-click easy mechanism, and no coding at all. How many days have you saved or could you saved knowing that attribute?

SkipValidation property can accept values like skipDataControls or validateCurrentRows. Please read more about it, maybe you'll find something more interesting than my post. The third page is for your own purposes, you can try to mix with the various values of these attributes :)

No comments:

Post a Comment