Wednesday, August 27, 2008

Soft delete with ADF entities

Say that you have a table created with this script,

create table users(user_name varchar2(20) primary key, name varchar2(100),active_yn varchar2(1) default 'Y')

And you want to set the active_yn to N when a delete occurs instead of doing a hard delete.

I found this solution working, I am still not sure whether it is the best way or not..

I created my entity by using the wizard . Then edit the entity and on the Java tab select the below check boxes to generate the required Java classes.

1-Generate entity object class
2-Remove method
3-Data manipulation methods

Then in the generated Java file change the remove and doDml methods as below

/**Add entity remove logic in this method.
*/
public void remove() {
setActiveYn("N");
super.remove();
}

/**Custom DML update/insert/delete logic here.
*/
protected void doDML(int operation, TransactionEvent e) {
if (operation != DML_DELETE)
super.doDML(operation, e);
else
super.doDML(DML_UPDATE, e);
}

-----

Then test your application and see that instead of doing a hard delete we are now setting a flag on the record when it is deleted.

Wednesday, August 06, 2008

Handling the navigation from a backing bean

Yesterday I was experiencing some login form, in which I am calling a backing bean when the login button is pressed. In the backing bean depending on the return of the operation call I want to redirect the navigation to the corresponding page. After doing some research in the forums I found the below solution. We use NavigationHandler class to redirect the flow of the application.


public String doLogin() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("login");
Object result = operationBinding.execute();
FacesContext context = FacesContext.getCurrentInstance();

NavigationHandler nh = context.getApplication().getNavigationHandler();

if (((String)result).equals("SUCCESS"))
nh.handleNavigation(context, null, "SUCCESS");
else
nh.handleNavigation(context, null, "ERROR");

return null;
}

ADF Methodology email list

Some ADF experts created a mailing list on Google to discuss the best practices with ADF.
Here is the link to be part of that group

http://groups.google.com/group/adf-methodology?hl=en

Saturday, August 02, 2008

Calling a PL/SQL function from ADF using JDeveloper 11G TP4



I will go over how to call a PL/SQL function from Jdeveloper 11G Tp4


First create a function that you will use , for this I used JDeveloper's database editor


Then create an ADF project and an Application Modulu within the new project. Follow the wizard until the Java screen, there we need to
check the first check box to generate the Java class file for the application module.
























Once you are done with the wizard you will see that a Java file was created under the application module.






Edit this file and add the a public method to call the PL/Sql API. For more information you can check the developer's guide documentation.












Now we need to expose this function .
To do this edit the application module and go to Java tab. There click the pen for client interface. You should the newly created function on the left side. Select it and move it to right.














After completing the previous step you
should be seeing your function under Data controls.


Everything is ready now. We need to create a page and drag and drop the data control on to the page




While dropping the data control on toyour page select ADF Parameter Form from the coming menu as in the left picture.This will create the form to call your function.




Once the form is created there is one more thing to do. We need add a field to see the result of the
function. To do this drag and drop the String item on the data control on your page as an output field as on the left.




Now we can run our page and test it.






Wednesday, July 23, 2008

JDeveloper 11G TP4

I started to work with the IDE 3 weeks ago. My company decided to migrate our existing forms application to ADF.
My first impression with IDE was not so positive but it is still a preview release so I hope it will be better once released.
I decided to write my experiences with this tool from now on..Lets see how it will be ..


Wait me JDeveloper , I am coming to explore you !!