Tuesday, March 30, 2010

Creating and displaying Popups in Oracle ADF

Hi all,

This post is about How to Create and display Popups in ADF application. In popups you can display different types of windows like Dialogs, NoteWindow,  Panel window etc etc.

In this post i will show displays popups dialogs by
-  Using  af:showPopupBehavior JSF tag on a Command button
-  Calling Javascript code using af:resource and af:clientlistener

Example Scenario:
In ADF table component when user double click any row a popup dialog will display to show which record the user has clicked. Also the same Action on simple button press. I am using Countries table in HR schema to displaying ADF read only table in a simple JSF page.

I assumed you have created JSF page with Read only table of CountiresView Binding and also has af:commandbutton after the table Form looks like this


Creating Pop-ups:
- Drop af:popup component any where on your JSF Page set its id as "poptable" and ContentType = LazyUncached. (Drop popup at some free facet)
- Drop af:dialog component inside popup component
- Set the property of af:dialog type to OK (to display only OK button in a dialog)  and
- Drop the CountryName field from DataControl to Dialog window
- Delete it ...Yes you read correctly its kind of Trick to create binding we will use it in a different way
- Drop af:outputText in Dialog set the Value to
"You have clicked #{bindings.CountryName} Country"

Your Structure window would be like this


Display popup on button click:
- Drop af:showPopupBehavior on af:commandbutton.
- Set the popId = poptable (our popup name) and type as action.

To display on Double click on table:
- Drop af:clientlistener on af:table component.
- Set the Method name as "showPopupFromAction" (Name of Javascript method we will create this method in a while) and choose type as "dblClick" for double click actions on Table component.
- Drop af:resource tag in your document set the type as javascript and Copy and paste the following code in the source
 Note:The af:resource tag is a way to include CSS and JavaScript in the document.





/** * Shows a popup from an
"action" type event. *
@param {AdfActionEvent}
actionEvent the event being
handled */
function showPopupFromAction(actionEvent) {
actionEvent.cancel();
var eventSource = actionEvent.getSource();
var popup = eventSource.findComponent("poptable");
popup.show();
}

Your structure window would be like this



At runtime Navigate to any record press Show popup button or Double click on record a Popup should display as shown in the slide



Download Working Example
 


Feel free to comment.

Cheers,
Baig

Sunday, March 28, 2010

Creating Master-detail form in Oracle ADF

Hi all,

Today i will show how to create simple master detail form in ADF which would help people coming from 4GL (Forms Developer) technology to ADF.

After completion of all steps the final result would be like this


Pre-requisites:
- HR Schema in Oracle database with tables Departments and Employees.
- Oracle Jdeveloper 11g 11.1.1.2.0 you can download from OTN.

Creating EO, VO, VL and AM (Entity Object, View Object, ViewLink and Application Module)

- Create new Application named masterDetailApp based on ADF Fusion template.
- Create Connection named hr.
- Create EOs based on ADFBC from tables Departments, Employees (demo.model.entities) package
- Create VOs names DepmentsView and EmployeeView based on those EOs (demo.model.queries)

- Create ViewLink (Viewlink is a Association or join condition between 2 View Objects) between VOs named DeptEmployeeVL.

- Right click on the package demo.model.queries and choose New View Link named it DeptEmployeeVL as shown in the Slide

Tuesday, March 23, 2010

ADF-How to find rows in an Iterator

Hi all,
As you might know that i came from 4GL background and these days i am exploring Oracle ADF.

Subject:


I am working on Sample Calendar application which i will post when i will complete it.
In that application I have 2 iterators named AdfCalendarIterator and AdfCalendarINSERTIterator based on same View object called AdfCalendarVO

I have created 2 instances of VO to separate CRUD (Create Read Update Delete) operations.

I was not able to find simple solution on Google so i decided to share for ADF newbies 

Solution:
On Managed bean write something similar
Note: I modified the example for understandability we assumed that we have only 1 column primary key


   //Primary key value if you have Number then replace with anotherVariable
    String currid = "A001"; 
   
    // 1. Access the binding container
    DCBindingContainer bc = (DCBindingContainer)getBindings();
  
   // 2. Find a named iterator binding
    DCIteratorBinding iter =
      (DCIteratorBinding)bc.findIteratorBinding("AdfCalendarINSERTIterator");
  
    // 3. Create a Key object 
    Key key = new Key(new Object[] { currid });
   
    //4. Get the RowSetIterator Object
    RowSetIterator rsi = iter.getRowSetIterator();
   
    //5. Find the row in the Iterator using findByKey funtion by passing Key object
    Row row = rsi.findByKey(key, 1)[0];
   
   // 6. Set the Current row in Iterator (findByKey does not Navigate to current row)
    rsi.setCurrentRow(row);  
 

For more detail on particular function or procedure right click on it in JDeveloper and select Go to Javadoc... also check Oracle Fusion Developer guide

Feel free to comment and post better examples.

Happy learning,
Baig

Sunday, March 21, 2010

How to Create ADF LOV with Filter or View Criteria

Hi all,

This week i will continue my last post about Creating LOV in ADF application and today i will create LOV on ManagerId Column which is different cause of 2 reasons

We would add following 2 business rules to the LOV

1) Manager cannot manage themselves i.e ( EmployeeId <> CurrentEmployeeId)
AND
2) Employee can be manage by other employees in the same department or in Executive Department which ID is 90.
(DepartmentId = 90 OR (DepartmentId = CurrentDepartmentId)

For this we have to create a View Criteria on our ViewObject (VO) that will filter the list based on few Bind Variables.

Steps:
Creating View Object (VO):


- Create new VO in adf.demo.model.queries package called EmpManagerLOV based on Employee entity with updateable is deselected.

- On Attribute page choose DepartmentId, EmployeeId, FirstName and LastName on Query page choose Order by as FirstName and LastName.


Adding Bind Variables to VO:

- Double click the VO EmpManagerLOV go to Query tab page in the Bind Variables section click the green + sign and Create 2 bind variables.
- Name CurrentEmployeeId Type Number Required No
- Name CurrentDepartmentId Type Number Required No



Sunday, March 14, 2010

Creating LOV in ADF Application

Hi,

This week i will continue to enhance my previous post (Moving to Jdeveloper11g Your First ADF Form) and today i will cover how to create LOVs in Oracle ADF application.

Pre-requisites:
- HR Schema in Oracle database.
- Download this basic completed application and change the connection settings according to your environment.


Objective:
On this post we will create LOVs for Job, Department Id in Simple Employee based form.
Note: (Manager LOV is little tricky i will cover in next post)


Steps to follow:
For good naming convention we will rename the adf.demo.model.view package to queries
- Right click on adf.demo.model.view in Model project and choose Re-factor > Rename and rename it to adf.demo.mode.queries


Adding Departments and Jobs Entities:
Note: If you already have entities in your project then you can skip to next step

- Add Departments Entity by Right clicking on adf.demo.model.entities package in Model project and choose New Entity Object
Enter Name as "Departments" and Choose Schema object as "Departments" by pressing Browse button you can select from the list of objects as well.


- Choose All columns in attributes page and click Finish.
- Repeat the same step for Jobs entity.

Monday, March 8, 2010

Moving to Jdeveloper11g Your First ADF Form

Hi all,

As you may know that i m playing with Oracle ADF and recently i have completed my First sample ADF application called TUHRA 2.0 following the steps from the Jdeveloper Handbook which is good book to start with (don't afraid of 600 pages of theory in the start before u to actually develop something) :)

So if u also want to learn something new then don't worry here is your first step.

In this Post we will create basic ADF form which is based of Oracle default HR schema's Table Employee later posts i will enhance this form by some LOVs and other stuff. At the end you can also download my completed example

Pre-requisites:
- Download and Install Jdeveloper11g from OTN Website
- Create default HR schema in Oracle database

Creating Application and Entity Objects:

- Open Jdeveloper Choose default role if asking.

- Choose New Application from  Menu

- Enter Application Name "MyFistJSF" Application Package "adf.demo" and Select Fusion Web Application ADF in Application Template



- Create Connection in Application Resource Section on the left pane named as "HrConn" and Test connection it should appear Success



- Click Right on Model Project choose NEW select Business Components from Tables Click OK as shown in the slide


- By Default HRConn Connection will appear Click OK and choose the Employee table to selected area set the Package name to "adf.demo.model.entities"

Click Next and skip all steps up to Application Module


- Named Application Module as HrModule and package to "adf.demo.model.services" click Finish



This process will create the Employee Entity with Application Module in the Model Project