Thursday, May 5, 2011

ADF BC : Throwing Dynamic Exception Message in Groovy

 

As we know we can use Failure Handling tab in validation to show error message.

However , my requirement is to show message based like error or warning or any different message in logic , so I have to go ahead with groovy coding.

I wrote two statement.

adf.error.warn("warning not error")

adf.error.raise("error not warning");

image

Here there is only one if statement there can be multiple if else if logic ,so we can throw the message as per logic.

I gave less salary and it throwed else exception.

image

ADF BC : Debuggin Groovy in ADF BC

 

Some time we need to write complex groovy in order to achieve some business purpose and we will ofcourse fall in to some issue that we need to debug.

Best idea is to use equivalent of sop in java to println in groovy.

image

Run ADF BC tested and give wrong salary. It will throw the exception , but main thing is we are interested in println statement that we can see in log window of jdeveloper.

image

ADF BC : Entity Object Groovy validation

 

We can take advantage of young groovy language.

Let us validate salary in employee and if it is more than some range then we will throw the exception. All declaratively !!

Double click salary attribute in Entity Object

image

Provide the error message.

image

After running ADF BC tester and giving salary more than 25000 , I tabbed out and it throwed following exception.

image

ADF BC : Entity Impl Validator

 

Every framework should allow extension and that is what exactly ADF too provides us.

We can create Validation Method for each entity in EntityEOImpl.java.

Here we have created ValidateJobId method and we can write logic inside this method to verify bunch of business logic like if jobid is in some range then do bla bla bla.

image

image

Wednesday, May 4, 2011

ADF BC : Validate Phone Number from Entity Object

 

I have seen one thing in ADF developer community that we don’t utilize power of ADF BC.

Let us try Phone Number Validation without writing any code.

Phone Number (xxx-yyy-zzzz) format.

I am expecting that you have HR schema available and you have already created Employee Entity and View Object.

Double click Phone number in Employee Entity Object and go to validation and select regular expression.

Select Phone Number and Click Use Pattern which will generate Phone number regular expression pattern.

image

Go to Failure Handling and give your custom message.

image

Now run the application , we all know it should only accept xxx-yyyy-zzzz pattern.

Let us try and it will throw following exception when we tab out to another field.

111-111.1111

image

That is really woow way of handling exceptions. You can find regular expression for Zip Code , Fax Number and other stuff that you will need for validation.

Tuesday, May 3, 2011

ADF BC : Creating Bind Variable at Run Time

 

By default we can create the bind variable for view object declaratively and set it value programmatically using

ViewObject viewobj = am.findViewObject(“voname”);

viewobj.setNamedWhereClauseParam(“depid”,123);

viewobj.executeQuery();

Dynamic Bind Variable

now suppose you want managerid as bind variable runtime.

viewobj.setWhereClause(“ManagedId = :managerid”); //:managerid is bind var

viewobj.defineNamedWhereClauseParam(“managerid”,null ,null);

viewobj.setNamedWhereClauseParam(“managedid”,234)

viewobj.executeQuery();

ADF BC : DeadEntityAccessException

 

This exception usually comes when you try to set the attribute for entity object whose row is physically deleted.

Example:-

You have overide remove and dodml method of EOImpl.java and you want to perform some logic before deleting the row.

Perform the logic before calling super.remove method ,otherwise , you will see above exception.

image

I ran application module tested and it throwed following exception.

image