Sunday, November 20, 2011

Custom Exception Registration for ADF BC EO Attribute

Sometimes customers prefer to implement business logic validation completely in Java, without using ADF BC declarative/Groovy validation rules. Thats fine, we can code business logic validation in ADF and implement different custom validation methods on VO/EO level. How to report validation message from custom method on VO/EO level? We can throw JboException, but it shows up on UI as popup. When custom validation is implemented for specific attribute, we would like to attach validation message directly to the attribute itself. Steve Muench helped us this week with EO Attribute Exception registration, I would like to share solution with you.

Download sample application - AttributeExceptionRegistration.zip. This sample implements custom validation method on VO Row Impl class, means custom logic can be applied per row:


If validation logic fails, we are calling our own validation failure method implemented inside EO Impl class. This method actually constructs AttrValException and attaches it to specific attribute using standard registerAttributeException(...) method. Validation message is retrieved from Message bundle. On the UI AttrValException will be rendered the same as declarative attribute level validation message declared on EO attribute. See detail code for attaching AttrValException here:


Validation message will be retrieved from Message bundle:


In this example, just for demo purposes, validation is triggered in UI from separate Action Listener method - just by calling custom validation logic from VO Row Impl:


Validation messages shows up nicely, directly attached to the attribute field:


8 comments:

Anonymous said...

Very Cool.

I am new to ADF.
Regarding,
"Validation message will be retrieved from Message bundle:"

How do I do it?

Thanks

Andrejus Baranovskis said...

In this specific case, message is retrieved using such code: http://4.bp.blogspot.com/-N9o31f5eKog/Tskj-bVHuwI/AAAAAAAAFpE/oKRTqjeIUEs/s1600/2.png

If you have more detail question, please post on our public RedSamurai wiki: http://redsamoracle.wikispaces.com/About

Andrejus

Makrand Pare said...

Hi Andrejus,

Thanks a lot for the post. I tried your example in my program however the error message appears only after second click not on first click. I'm using JDev 11.1.1.5. What could be the reason?

Thanks,
Makrand

Ajith said...

Hi Andrejus,

Thank you very much for your post.

I have a clarification. We have a method validation in EO which is deferred to transaction level which actually checks whether one column in a table is empty or not. If in any of the rows, the value is null the validation will throw an error message. Please update whether we have any way to show an attribute highlighted error message in this case.

PS: we have clicktoedit enabled for this table

James Tran said...

In Jdev 11.1.1.7, on the 1st click, it will work as you explained. However, on the 2nd click, ADF will throw an exception:

ADFc: No exception handler was found for an application exception.
java.lang.NullPointerException
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeDef(JUCtrlValueBinding.java:544)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getHintObject(JUCtrlValueBinding.java:2082)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getHint(JUCtrlValueBinding.java:2077)
at oracle.jbo.uicli.binding.JUCtrlValueBinding.getLabel(JUCtrlValueBinding.java:1944)
at oracle.adf.controller.faces.lifecycle.Utils.buildFacesMessage(Utils.java:169)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addMessage(FacesPageLifecycle.java:211)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addError(FacesPageLifecycle.java:320)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addError(FacesPageLifecycle.java:336)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addError(FacesPageLifecycle.java:336)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addError(FacesPageLifecycle.java:304)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.addError(FacesPageLifecycle.java:304)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.reportErrors(FacesPageLifecycle.java:154)
at oracle.adf.controller.v2.lifecycle.PageLifecycleImpl.prepareRender(PageLifecycleImpl.java:579)
at oracle.adf.controller.faces.lifecycle.FacesPageLifecycle.prepareRender(FacesPageLifecycle.java:82)
at oracle.adf.controller.v2.lifecycle.Lifecycle$9.execute(Lifecycle.java:224)

Andrejus Baranovskis said...

This was tested with previous ADF releases, perhaps in 11.1.1.7 some tweak is required. If I will have time, I will check it.

Andrejus

Uma Venkatakrishnan said...

Hi,

I am using 12.1.2. I face the same problem of null pointer exception in the second click. I see that you have mentioned some tweaking is required to get around this issue. can you share what that is.

Thanks
Uma

Ashok Reddy Singam said...

Hi Andrejus,

I am using 11.1.1.7.1. Facing same issues as others.
1)First click is not doing anything
2)Second click i see validation msg as expected
3)Third click below exception oracle.jbo.uicli.binding.JUCtrlValueBinding.getAttributeDef(JUCtrlValueBinding.java:581).

In case if you have any workaround to fix then please share with us