Wednesday Jun 27, 2012

Using Exception Handler in an ADF Task Flow

Problem Statement:

Exception thrown in a task flow gets wrapped in an exception that gives an unintelligible error message to the user.

Figure 1

Solution 1. Over-writing the error message with a user-friendly error message.

Figure 2

Steps to code

1. Generating an exception: Write a method that throws an exception and drop it in the task flow.
2. Adding an Exception Handler: Write a method (example below) to overwrite the Error in the bean or data control and drop the method in the task flow.

Figure 3

This method is marked as the Exception Handler by Right-Click on method > Mark Activity> Exception Handler or by the button that is displayed in this screenshot

Figure 4

The Final task flow should look like this. This will overwrite the exception with the error message in figure 2.
Note: There is no need for a control flow between the two method calls (as shown below).

Figure 5

Solution 2: Re-Routing the task flow to display an error page

Figure 6

Steps to code

1. This is the same as step 1 of solution 1.
2. Adding an Exception Handler: The Exception handler is not always a method; in this case it is implemented on a task flow return.  The task flow looks like this.

Figure 7

In the figure below you will notice that the task flow return points to a control flow ‘error’ in the calling task flow.

Figure 8

This control flow in turn goes to a view ‘error.jsff’ which contains the error message that one wishes to display.  This can be seen in the figure below. (‘withErrorHandling’ is a  call to the task flow in figure 7)

Figure 9

Monday Jun 25, 2012

View Link inConsistency

What is View Link Consistency?

When multiple instances (say VO1, VO2, VO3 etc) of an EO-based VO are based on the same underlying EO, a new row created in one of these VO instances (say VO1)can be automatically added (without re-query) to the row sets of the others (VO2, VO3 etc ). This capability is known as the view link consistency. This feature works for any VO for which it is enabled, regardless of whether they are involved in a view link or not.

What causes View Link inConsistency?

View Link Consistency for a VO could be disabled by disabling jbo.viewlink.consistent for the VO (or globally), or by applying setAssociationConsistent(false). Otherwise, any of the following can cause View Link inConsistency. 

1. setWhereClause

2. Unreferenced secondary EO

3. findByViewCriteria()

4. Using view link accessor row set

Why does this happen - View Link inConsistency? Well, there can be one of the following reasons.

a. In case of 1 & 2, the view link consistency flag is disabled on that view object.

b. As far as 3 is concerned, findByViewCriteria is used to retrieve a new row set to process programmatically without changing the contents of the default row set. In this case, unlike previous cases, the view link consistency flag is not disabled, meaning that the changes in the default row set would be reflected in the new row set. 

However, the opposite doesn't hold true. For instance, if a row is deleted from this new row set, the corresponding row in the default row set does not get deleted. In one of my features, which involved deletion of row(s), I observed that my changes were not reflected on UI. To resolve this apparent "view link inconsistency" issue, I replaced findByViewCriteria by applyViewCriteria.

b. For 4, it's similar to 3 - whenever a view link accessor row set is retrieved, a new row set is created.

Now, creating new row set does not mean re-executing the query each time, only creating a new instance of a RowSet object with its default iterator reset to the "slot" before the first row. Also, please note that this new row set always originates from an internally created view object instance, not one you that added to the data model. This internal view object instance is created as needed and added with a system-defined name to the root application module.

Anyway, the very reason a distinct, internally-created view object instance is used is to guarantee that it remains unaffected by developer-related changes to their own view objects instances in the data model.

JUnit: How to access rootAM from within nestedAM?

In normal model project, the way to access root AM from within nested AM is simple -

RootAMImpl rootAM =  (RootAMImpl)this.getRootApplicationModule();

However, the same approach doesn't help in JUnit model project. Use the following approach - 

Inside setUp() method --  RootAM rootAM =  (RootAM)Configuration.createRootApplicationModule(ROOT_AM, ROOT_AM_CONFIG);

Inside tearDown() method -- Configuration.releaseRootApplicationModule(rootAM , true);


ADF Tips and Tricks


June 2012 »