Thursday, May 26, 2011

ADF GUI : Selecting Multiple Row in af:table

 

There is business requirement sometime to select multiple row from af table component and do some operation during button click.

There are various ways of doing that and I will try to extend this same blog post in trying to explain you various ways.

1. First approach to select multiple rows.

In this approach we will have following things.

a. create simple ADF project and drag and drop regionview object from sample HR schema to JSF page as table and select the following radio button for multiple select which is not available in previous version of jdeveloper. So if you are using other version of jdeveloper then delete SelectionRowKey  and set rowselection to multiple.

image

Here is table definition

image

Three important property here is

selectionListener ,  rowSelection, binding

Now we will place some button to print multiple row selection.

Don’t forget that we need to have binding for table component in managed or backing bean.

image

Write this following code in button action or actionlistener method.

I have given adequate explanation in commented part.

image

I selected multiple region and it printed in the log window.

I will post other ways of doing same thing in different adf layer tommorow.

Wednesday, May 25, 2011

ADF BC: Debugging and Printing Runtime queries with bind variable and value

 

There are times when we don’t know what bind variable value is provided to query during run time.

We can easily check that by setting following option in jdeveloper.

Right click viewcontroller ,if you are running JSF or right click Model project if you are only running app module and go to project properties.

Then go to following tab and set the flag.

jbo.debugoutput=console

image

ADF BC : Validation Order

 

Entity level attribute are validated in order as specified and then finally entity level validation occur when transaction is committed.

ADF BC : Attribute level Validator

 

I have seen newbie in ADF with java background writing their own validation logic in backing bean or managed bean.

I would suggest them to dig inside attribute level declarative validation provided by Entity Object.

image

You can perform any type of validation using this rule , I bet because you can even write your own method in EO and call it from this rule.

There are in built compare , length and more validation . You can even write method in EOImpl.java and call it from here. You can even write your java code ,groovy code in script expression.

Please try to put as much as validation here because that is best practice in ADF.

Try to reduce as much as possible ViewController level validation.

image

ADF BC : Controlling Validation Order for attribute.

 

There are some validation rule in ADF BC entity object where you can control when that rule will fire.

Create new entity validator and do the following.

image

When you do tab out from that field then rule will fire immediately ,if you have selected below radio.

Otherwise , if you have selected second radio button then rule will fire during commit time.

image

ADF BC : Create method in View Object and call it from managed bean or JSF

 

In previous blog I mentioned how to call method in application module from gui and managed bean. Here I will explain you how to call method from gui and managed bean that is in View Object implementation class.

How to make sure that we create method in right impl class depent on your scenario.

If you are having business logic that is pretty generic and not specific and which utilize many VO/EO then go for applicatino module.

If you are having business logic that is specific to only view object and associated view object then go for method in view object impl class.

I created a method in vo that will show employee count.So I followed the same step to generate view object java classes as appmodule.

image

I wrote following method to show employee count.

image

When I exposed the method it came in data control inside employee view object instance.

image

Now I can drag drop this as button , link or even call from managed bean as mentioned in previous blog.

image

ADF BC : Create Method in Application Module and Exposing to Managed Bean

 

If you application need to perform some business operation with multiple entity and view object then best place to put your method Is application module implementation class. I will explain you here just how to use application module method from managed bean.

Create simple ADF Fusion project and double click application module and generate Impl class by going to java tab.

image

Then open impl.java class and write you own java method.

image

How to call this java method from button , hyperlink or even manage bean.

We need to expose this method before calling it.

I opened the client interface and shuttled that method to application module. Now this method will be visible in data control along with viewobjects that are exposed.

So it is as simple as this. This way you can write multiple method for various business operation like PaySalary , IncreaseSalary and more.

image

You can also see that there are other client.java file created to managed this.

Command Button calling this method

I created JSF page with one managed bean in back bean scope , you can also create backing bean.

image

If you refresh the datacontrol window then you will see that method as below.

image

Now just drag and drop this method on JSF page as button or hyperlink and run the page.

If you click the button you will see that sop statement is called and it is printing the message.

image

Calling method from managed bean

Drag and Drop command button on page and double click it and create a method in managed bean.

write following code and run the application and you will see the same printed message as before.

The advantage of calling from managed bean is ,if you have any GUI logic here that will decide which method to call then it is right place.

Eg:- do I need to call salary decrease or salary increase.

image

Tuesday, May 17, 2011

Composite Associations

When you create entity object based on database table having FK (Foreign Key Constraints) then by default following Association object behavior will be created between two table.

CREATE TABLE table_name
(
   column_id number(10),   
   column1 varchar2(20),
   FOREIGN KEY (column_id)
   REFERENCES table_23(xxxx_id)   
);

No Composite Association

image

If we try to delete a record , let us say we are deleting department that is having associated employees then it will throw or we are deleting order which has orderitems then following exception will be thrown because we cannot delete the parent until child record are present.

oracle.jbo.DMLConstrainstException

image

Implement Cascade Delete

If we select this option and tries to delete department that has associated employee or let us say try to delete order which has multiple orderitems then orders and orderitems get deleted without throwing DMLConstrainstException.

Because here this check delete all associated child record and then parent record.

image

This setting will fire DELETE statement in transaction commit time to make permanent changes.

Optimize for Database Cascade Delete

CREATE TABLE table_name
(
   column_id number(10),   
   column1 varchar2(20),
   FOREIGN KEY (column_id)
   REFERENCES supplier(column_id)
   ON DELETE CASCADE
);

When we generate BC and if our constraint in database has ON DELETE CASCADE then by default Composite Association is created with following check.

As we can see ‘Optimize for Database Cascade Delete’ is checked and Implement Cascade Delete is checked ,but disabled.

image

DELETE statement will not be fired during transaction on assumption that database has ON DELETE CASCADE constraint that will handle the deletion of corresponding rows.

Sunday, May 15, 2011

Quotes of the day

 

"Carry the burden smilingly and cheerfully, because patience is the key to victory." - Rumi

Monday, May 9, 2011

ADF GUI : Some Implicit Object on JSF , JSFF Page

 

#{data}
#{bindings}
#{facesContext}
#{adfFacesContext}
#{view}
#{cookie}
#{header}
#{headerValues}
#{initParam}
#{param}
#{paramValues}
#{requestScope}
#{sessionScope}
#{applicationScope

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