Friday 2 September 2011

Master Detail Relationship in ADF

 In real world we often need to build master detail application where we need to perform CRUD operation using Master to Detail.
We can easily obtain this in ADF. How we can obtain this and what functionalities we can provide easily are described below.

As for every ADF Web application we build two projects one is Model and another is ViewController.
We can build ADF application in both the approaches Model Design to UI Design as well as UI Design to Model Design.
We have followed Model Design to UI Design.
First we created the Business Components for this demo.


I created the Entity Objects first, then association between entities. I then built View Objects and View Links between them. I then included the View Objects in our Application Module.
We must have the view links created for creating master detail relationship.






 



I then created our UI in ViewController project.
I created ADF Table using master View Object for Departments.  
Then I created our slave table using slave View Object Employees.
We should be able to select rows in master table. Otherwise we will not be able to change the slave table.

Now if we select any department in the master table then the employees belonging to that department will be automatically populated in slave table.


 
We can perform CRUD operations on both the master and slave(s).  As shown in the below screenshots.



Hope this can help you ........... :)

Monday 2 May 2011

Unit Testing Of ADF Business Components Using JUNIT

In every project it is required to do proper testing, such that every requirement is met. There are many type of testings done in projects like Unit testing, Regression testing, Alpha testing etc.. From developer perspective unit testing should be done properly. In java , j2ee projects we normally use JUNIT framework. There are other frameworks also to do testing.

In ADF application also we will use JUNIT to do unit testing. To use JUNIT we need JUNIT extension for JDeveloper. For testing BC4J components we need BC4J - Junit extension for JDeveloper.

In the following application we have created one ADF model project using HR schema's Employee Table.

We have created entities, views as well as AM (named HRDemoAppModule).



First I have selected Business Components Test Suite to generate all the test fixture, test cases and test suite.
To create the suite I have selected the configuration HRDemoAppModule
.



It will create all the test cases. Now if we run the test suite we will see that all the tests were successful. Now I want to create my own test method . I want to test the data volume is correct or  not.  




Now as Oracle Database has 107 records. So I have added assertEquals. Do not forget to add @Test before the method under test.




The test succeeded.

In this way we can do unit testing of BC4J components such that code is bug free one.

Please comment..

Wednesday 27 April 2011

Export Collection in ADF

In many report based or any other data related application export to excel feature is always required.

Export to excel feature can be achieved in ADF very easily, may be just in 10 minutes we can see the result excel sheet. To achieve this in this project I have first created ADF business components from HR.Employee table. Then I created one jspx page to display the employee details table. Now I want to export this  tabular data in one excel named Employee.xls.  want that the employee details data will be displayed under title "List Of Employees " title. 

Now as export to excel will be available on some action so I added one command button here named "Export Collection"


I have inserted one exportCollectionActionListener inside the command button. This takes 5 parameters, 2 of them are mandatory.
Mandatory fields are:

ExportedId: The table or collection id you want to export

Type: The export type. As it is excel here it should be excelHTML

I have provided values for other two optional  fields :

filename: I wanted that the file name should be Employee.xls

title: I wanted the title to be here "List of Employees"


Now if I run the page and click the command button "Export Collection" it will export the table data in one Excel Sheet named "Employee.xls"



The title of the sheet should be "List of Employees " as shown below.




Please comment ....... 
If source code is required please email me.

Friday 22 April 2011

Separate Database As Well As Table structure For Pages


It is some time required to use separate databases as well as separate table structure for separate pages. Or even in same page we can use separate databases. 
In ADF it can be achieved very easily. I am discussing here the simplest one. ApplicationModule in ADF can be compared with persistence units of JPA, not exactly though as ApplicationModule has a lot of  features that persistence units do not. I have compared with persistence unit as in ApplicationModule configuration also we provide the database information. 
In JPA we use different persistence units to define separate databases and use those persistence units when required.
Similarly here we will be defining to different application modules for two different connections. Now we will distribute the view objects accordingly. 


Please see the pictures 



In the example I have used two databases MGR and HR

I have configured MGR in  AppModule2 and HR in AppModule1

Now the view objects using MGR database will be configured in AppModule2 and  view objects using HR database will  be configured in AppModule2.


Now if you see the picture above you can see two separate data controls.

I have created two separate pages for separate data controls. untitled1.jspx uses AppModule1DataControl, untitled2.jspx uses AppModule2DataControl.

I have created one button in each of the pages for navigation between two pages, and configured the navigation in unbounded task flow. 



Now if I run the pages you can see that In First Page Data from HR database is being displayed while navigating to second page through the button, displays data from MGR database.





So you can easily achieve this using two different application modules for different databases. 

This feature can be achieved by different methods like using Factory Classes, setting  JDBC_DS_NAME etc..


But I wanted to use the simplest one.
Please comment........



Monday 11 April 2011

File Download In ADF

It is common requirement in many projects to have file download facility.
File download facility can be achieved by many means, but in 11g + versions we have one very good component
to handle file download facility very quickly.

In 11g + versions we have one listener component called fileDownloadActionListener. Which can be triggered from any command related components like commandButton , commandLink etc.

It has three parameters filename, contentType, method.

filename : It is used to display the file name in response


method:   The method will be present in managed bean. It is used to handle the file download related activities. Signature of this method is

public void <method name> (FacesContext context, OutputStream out) throws IOException
                {
                    ...... your code...
                 }

contentType: It is used to specify the content type.(like it is word document or pdf document etc.)

In the below example I have used fileDownloadActionListener with commandLink.


<af:commandLink id="cl1" text="#{row.fileName}"
                                              partialSubmit="true"
                                              binding="#{fileDownloadBean.downloadLink}">
                                <af:fileDownloadActionListener filename="#{row.fileName}"
                                                               method="#{fileDownloadBean.download}" ></af:fileDownloadActionListener>
                              </af:commandLink>

The method referred is



    public void download(FacesContext context,
                         OutputStream out) throws IOException {
        File f =
            new File(this.directoryPath.getValue().toString() + "/" + downloadLink.getText());
        FileInputStream fis;
        byte[] b;
        try {
            fis = new FileInputStream(f);

            int n;
            while ((n = fis.available()) > 0) {
                b = new byte[n];
                int result = fis.read(b);
                out.write(b, 0, b.length);
                if (result == -1)
                    break;
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
         out.flush();
    }

So whatever file I want to download it will be downloaded using this listener. The coding type will be least one.



Please comment...

Friday 25 March 2011

Setting AM Parameters at Server Startup

It is always possible to set the am p[arameters like jbo.ampool.initpoolsize , jbo.dofailover etc while starting a weblogic server. It will be applicable for all the applications deployed in the server. To do this we must set the environ ment variable without tampering the default setDomainEnv.cmd or startWebLogic.cmd file.


To do this I have created one custom script

For my case the domain's bean location is D:\Oracle\Middleware\user_projects\domains\LoanDeliveryDomain\bin

My script looks like below


cd \
D:
cd Oracle\Middleware
cd user_projects\domains\LoanDeliveryDomain\bin
set JAVA_OPTIONS=%JAVA_OPTIONS%
set JAVA_OPTIONS=%JAVA_OPTIONS% -Djbo.ampool.initpoolsize=110
set JAVA_OPTIONS=%JAVA_OPTIONS% -Djbo.ampool.minavailablesize=50
set JAVA_OPTIONS=%JAVA_OPTIONS% -Djbo.dofailover=true
startWebLogic.cmd

as I am using windows environment. It should be almost same for unix environment also.

Now if I start the server it will be automatically set during server startup

Below is the screenshot



Please add comments :)


Monday 7 March 2011

ADF Popup

Like any web application it is required to show pop up window in certain cases in ADF also. In ADF it can be shown in  many ways. Like we can show popup using javascript, using taskflow using pop up component etc. Here I have discussed ADF's popup component for showing the pop up, the simplest one I think. To show popup I first made one web application with one test page.



I have added one command button. I will show the popup for buton action.


I have added one <af:popup> component in the page as shown below in the below page. Added one dialog in that popup window.



Now I want to show the popup window on button action so I have added <af:showPopupBehavior> inside the command button component.



In show popup behavior I have added the popup id and button action.


Now if I run the page and click the button it will show the popup window.




This popup window can be shown from managed bean also.