Sunday, March 13, 2011

Exception Handler for Method Calls inside ADF Task Flows with Fragments

In regular case, when JboException is thrown from the Model, it is rendered in UI within popup component automatically. This works fine, when we are calling operation bindings directly. However, if operation is called through ADF task flow Method Call - JboException is being catched by Controller layer and is rendered differently. Exception handling for ADF task flows with pages can be done slightly differently, I will explain it in my next post.

Download sample application - MethodCallExceptionHandler.zip. This sample app contains one customer method in Application Module implementation class, where JboException is being thrown:


This method is exposed to the ViewController through Data Control:


ADF task flow Method Call activity is implemented to invoke processData() method, which throws JboException:


On runtime, when JboException is encountered from Method Call activity, we are getting browser error:


This can be avoided by defining single ADF task flow Template with only one activity - Method Call marked as error handler:


In the case, when we have ADF task flow with fragments, there is no need to implement error handler method - exception is handled and popup will be rendered automatically. Only what we need to do is to define error handler ADF task flow activity as shown in the screenshot above.

In order to define error handler method activity ones, we are using ADF task flow Template. All ADF task flows, where we want to handle JboExceptions for Method Calls should be based on that template:


In a case when JboException will happen, user friendly popup with error text will be rendered to the user:


14 comments:

Sashika said...

Hi,

I just imported your application to 11gR2 and ran as is. But upon clicking the process data it does nothing, no popup error messages i dont see a stack trace also. I checked the AM method is definitely being called also.
What could be the case, is it R2?

Andrejus Baranovskis said...

Hi,

Yes, method is invoked - I tested. But it looks like JboExceptions are not raised in R2 - looks like R2 bug.

Andrejus

Anonymous said...

Hi,

Can I personalize the text of the exception?

Thanks

Andrejus Baranovskis said...

Yes, check first screenshot - you can set your text.

Andrejus

oceans said...

Hi,

Will the same error handling happen if there is a error in the page fragment's pageDefinition ControllerClass ?

Regards,
Vijai

Andrejus Baranovskis said...

Please specify, what you mean by Page Definition Controller class?

Andrejus

oceans said...

I mean to say that the page definition file of the page fragment includes a attribute ControllerClass.

To this a class is assigned which extends RegionController. These have a set of methods which are invoked on every activity performed say the refresh.

I have my validation in the refresh method where the Exception raises....

Andrejus Baranovskis said...

And exception is not handled in your test by TF exception handler?

Andrejus

oceans said...

Nope I modified your sample in this post. And it didnt.... :(

Vijai

oceans said...

Hi Andrejus,

Any idea off how to catch the above mentioned exception please ?

Vijai

Andrejus Baranovskis said...

I did not reproduced it.

Andrejus

Subba said...

Hi Andrejus,

We have a defalut method activity in a TF. which is a AM method, and we would like to thrwo JboException and that we want to handle it by ErrorHandler and show as a popup on the UI.

In our case before page renders itself, as part of default method activity of TF we are throwing the exception. So though i followed the steps you mentioned in this Blog, I am not able to see the popup in UI.

We have used the TF as a region onto a Jspx and it is failing with the below exception .

java.lang.IllegalStateException: The expression "#{bindings.NotificationWorklistFlow1.regionModel}" (that was specified for the RegionModel "value" attribute of the region component with id "r1") evaluated to null.

in Debug mode i have checked that controlis going to Default method activity and it is executing thorw new JboException statement. But we are not getting it to UI.

Any Help on how to show the JboException from default activity to UI?

Thanks for your help!!

Phuu Tek said...

Hi Andrejus,

Thanks for posting this code.

Your code somewhat mimics mine so I had somewhat modified your code.

If you may have the time to look
http://www.4shared.com/zip/yoc_GQdx/MethodCallExceptionHandler_2.html


My use case is that, what if I have a method call as the default activity of the jobs-form-flow and it has raised an exception.

I somehow need to display the message of the exception and I dont want the jobs-form page to load.

I tried it with your code but I cant seem to get the exception message.

Any idea please?

Thanks

Andrejus Baranovskis said...

Hi,

In ADF 11g R2, it works if you get Current View Port, instead of Current Root View Port. This should work:

ViewPortContext currentViewPort = context.getCurrentViewPort();

Just update controllerExceptionHandler() method.

Regards,
Andrejus