Sunday, June 27, 2010

Integrating external webserives into ADF fusion application

Hi,

One of the use cases always comes to desk is to validate that user has entered a valid email address or not? now question is how to verify that the email address is valid? so answer is with the power of webservices we can verify that the email address is valid or not so again....


How to Integrate WebServices in Fusion application? As far as i know there are 2 methods.
1) By creating webservice data control on WSDL document provided by producer.
2) By creating webservice proxy.

Download the completed example 

In this example we will look at the first method Webservice data control:
- We will integrate external web-service which will return result TRUE or FALSE based on email input parameter.
- When user will enter email address in a field the appropriate message will appear with the field.
- On Commit we will also verify the output of the  the method to take further action.


Getting the Web service 
Visit http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=22 and get the address of WSDL document thats all you need to integrate.
 (This can be any site who provides web service)


Test the webservice on the site by entering any email address and press invoke

Webservice will return the boolean value based on input

Lets integrate this webservice into out ADF fusion application

Create a table in HR schema to use in example

create table person_emails
(person_name varchar2(60),
 person_email varchar2(30));

Create Fusion application and Data control
Create Business components from table for person_emails table with application module
Right click Model project and select new follow the slides

Copy and paste the WSDL location and paste into URL field and press Service button to validate.

Select the methods you need to integrate in this service we have only one method


Next Next Next Press Finish

Now we have created a Data control so we can use it on JSF Page

Create a JSF Page
- Drag a collection of PersonEmail1 from data control panel to the page as ADF Form
- Now expand EmailWSDC data control and drag the Boolean Return below the Email field and Formatted output text

- Binding dialog will appear asking you to provide value from email parameter.
expand the expression builder and choose PersonEmail input value as shown in the slide.


as you can see the method is appearing in Page binding section as well

Set AutoSubmit = TRUE of PersonEmail field
Add a partial triggers property of Output text linking to the Email field 


Calling Web service Method
Choose edit from the property inspector in the ValueChangeListener of Email field and create a Managed Bean



Define Bean method by pressing New


In backing bean write code similar to this
The code is executing the Action method which is already linked in the page binding by passing the current value in the email field to the parameter called "Email"


package baigsorcl.view;

import java.util.Map;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;

import oracle.adf.model.BindingContext;

import oracle.binding.AttributeBinding;
import oracle.binding.BindingContainer;
import oracle.binding.OperationBinding;


public class Page1Bean {

    public Page1Bean() {
    }
    
    String emailResult;

    //Method to call webservice Action Method
    public boolean verifyEmail(String email) {
        BindingContainer bindings = getBindings();
        OperationBinding method = bindings.getOperationBinding("IsValidEmail");
        Map paramsMap = method.getParamsMap();
        
        //assigning parameter
        paramsMap.put("Email", email);
        Object result = method.execute();
        
        if (result.equals(true)) {
            emailResult = "Thank you for providing valid email address";
            return true;
        } else {
            emailResult = "Please provide valid email";
            return false;
        }
    }

    //value change listener
    public void verifyEmail(ValueChangeEvent valueChangeEvent) {
        if (valueChangeEvent.getNewValue() != null) {
           boolean result =
verifyEmail(valueChangeEvent.getNewValue().toString());
        }
    }

    public BindingContainer getBindings() {
        return BindingContext.getCurrent().getCurrentBindingsEntry();
    }

    //On commit Action
    public String commit_action() {
      
       //Retreive Attribute value of email id
       BindingContainer attrbindings = getBindings();  
       AttributeBinding attr =
       (AttributeBinding)attrbindings.getControlBinding("PersonEmail");  
       boolean emailExists = verifyEmail(attr.getInputValue().toString());
      
       //if method returns TRUE then commit else error message
       if (emailExists){
        BindingContainer bindings = getBindings();
        OperationBinding operationBinding =
            bindings.getOperationBinding("Commit");
        Object result = operationBinding.execute();
        if (!operationBinding.getErrors().isEmpty()) {
            return null;
        }
        return null;
       }
       else {
         FacesMessage msg = new
FacesMessage(FacesMessage.SEVERITY_ERROR, "Error" , "Please provide valid email to continue...record not saved");
         FacesContext.getCurrentInstance().addMessage(null, msg);
         return null;
       }
  
    }

    public void setEmailResult(String emailResult) {
        this.emailResult = emailResult;
    }

    public String getEmailResult() {
        return emailResult;
    }
}

Assign the emailResult Variable to the Result output text we create for proper message



- Run the Page enter invalid email address and tab out message will appear about invalid email address enter any valid email address and tab out or press commit

Press Commit you will see the alert error if email is invalid


finally enter valid email and all is well


Explore more detail in the example

More reading about Integrating webserives check here

Happy JDeveloping,
Baig

Saturday, June 26, 2010

Migrating APEX 3.2 to APEX 4.0

Hi all,

Yesterday i migrated APEX 3.2 to 4.0 on my local XE database and it went smoothly, i thought it would be good to share with you some tips. One of the coolest thing is APEX 4.0 installer migrates automatically all meta-data from your old installations.

One of the main features i like in APEX 4.0
- Team development.
- Dynamic Actions.
- Flash charts.
- Better themes including maps (which is good enough to impress management for geographical reporting)
and many more to explore :)

Steps to follow:

1) Your database must be 10.2.0.3 or greater (else you will waste lot of time as my manager did yesterday LOL ... ) (if you have oracle XE install then no worries)
also make sure that Oracle Text and XML DB is installed and configured

2) Backup you database and all applications (good practice)

3) Unzip Apex 4.0 folder to some folder other than 3.2 apex i copied into
   C:\oracleXE\app\oracle\product\10.2.0\server
the folder must be named as apex (without any version name)

4) Run the installation scripts

Full development installation

c:\cd  c:\oracleXE\app\oracle\product\10.2.0\server\apex
c:\ sqlplus sys/mypassword as sysdba
sql> @apexins.sql SYSAUX SYSAUX TEMP /i/


Load Images


c:\cd  c:\oracleXE\app\oracle\product\10.2.0\server\apex
c:\ 
sqlplus sys/mypassword as sysdba
sql> @apxldimg.sql c:\oracleXE\app\oracle\product\10.2.0\server

Note: Dont give complete path with apex  folder

Change ADMIN password if required (script will prompt for password)


c:\cd  c:\oracleXE\app\oracle\product\10.2.0\server\apex
c:\ 
sqlplus sys/mypassword as sysdba
sql> @apxchpwd.sql  




Thats all while installing you will see the above message means your old apex installation is migrating to new one.

Run the apex home page as http://localhost:8080/apex you will see new interface


Perform post installation tasks

More info at Oracle APEX installation docs

Have a nice day,
Baig

Saturday, June 19, 2010

Display LOV on F9 Key in Oracle ADF

Hi,

Recently i learned from OTN forums how can we display LOV by pressing F9 key on field (which is Oracle forms default key to display LOV and migration to ADF would required developers to keep the common features alive) the answer is by using JavaScript we can control which key has been pressed by user or which mouse button is pressed without a round trip to server.

Lets get into example:

- Create Simple LOVs on Employees table's field 'DepartmentId' and 'ManagerId'

- Create metaContainer facet in af:document (Recommended area to put javascript code)
- In structure window right af:document and choose insert inside > JSF Core > facet

- Choose metaContainer from list and press OK

- Drag af:resource component to metaContainer facet from Component palette and choose type 'javascript'

- Go to page source and create a function showMyLOV as shown in the slide
Note: You can ignore any errors in the structure window regarding "Expected name instead of &."

- Add a client listener to the field you want to display Lov on F9

- Run the page and test


Download the example

More Reading on JavaScript implementation in Oracle ADF check Webuser Interface  guide

Happy JDeveloping,
Baig

Wednesday, June 16, 2010

Working with Dynamic Regions in Oracle ADF

Hi all,

I will extend my old post "Creating Pages with Regions in Oracle ADF" here so now i will show you how to work with Dynamic Region.

Note: Updated on 23-Sep-2010 Identified bug in the sample code. Thanks Asim and Pino

What is Dynamic Region? 

According to Oracle docs:
An ADF dynamic region is an ADF region where the task flow binding dynamically
determines the value of its taskFlowId attribute at runtime. This allows the Fusion
web application to determine which bounded task flow to execute within the ADF
dynamic region based on the result of evaluation of the task flow binding’s
taskFlowId attribute.

In this example:
- We will have 2 Bounded task flow one will show the list view of the Employee table and other shows the form style view
- We will have a home page with 2 different button to activate the particular region.

As shown the runtime view of the use case.




Steps to follow: 
(I assumed you already have enough ADF experience now if not feel free to check ADF section on this blog)

1) Create 2 bounded task flows with page fragments, named list-flow and form-flow respectively.
2) Create view activities on these pages one each.
3) Drag and drop the collection from data control and design your page as your taste.
4) Create a new activity in adfc-config flow called Home
5) Create home page by choosing default 2 column template as shown in the slide


6) Create 2 button on the first facet labeled as List and Form respectively.
7) Drag a List-flow to second facet and choose Dynamic Region from the menu
8) Create a Managed Bean named "DynamicRegionBean" class "DynamicRegion" Press OK Scope must be viewScope
9) We are not passing parameters to our Task flow so we will keep this default press OK
10) Change the code in the DynamicRegion class as following the method getDynamicTaskFlowId()  returns the TaskflowId of the BTF so we have changed our code to return the ID dynamically


11) Drag and drop af:setPropertyListener to both buttons on HOME page set values to static string as 'list' and 'form' respectively as shown in the slide

12) Set the partial submit to true on both these buttons and set partial triggers property to button ids in af:region component.

Thats all you are ready Run the page Press Form button the form-flow will appear press List button the other view appears




More Reading: Oracle Fusion Developer Guide Working with Dynamic Regions

Download the example workspace


Note: This example is to show how to Dynamic Regions works, When you have more than couple Regions then its better to write the Region code logic in a separate java class for ease of maintenance and import that class in DynamicRegionBean class.


Have a nice day,
Baig

Saturday, June 12, 2010

Converting Text to Upper Case in Oracle ADF

Hi all,

Just got to know the cool solution using Javascript at OTN forums i feel it would be better to share it.

If you want to convert a text of field to uppercase 2 possible solutions in my opinion

Solution 1:
  - JavaScript code which converts the text to uppercase using af:resource tag
  - link the function with the InputValue of the component.

Solution 2:
- Covert the value in setter method of the ViewObjectImpl class


Solution 3: (Updated on July 10, 2010)
Found great and better solution by Chris Muir (better than mine)

In this example:
- I will use Solution 1 on the First Name field
- I will use Solution 2 on Last Name field.

Note: Solution 1 in my opinion is better choice which is faster and less overhead on application


Solution 1 by Frank Nimphius
Here is the post by Frank Nimphius

1. drag and drop an input text field to the filter facet of a column2. create a JS function as shown below
3. Drag and drop an af:clientListenener to the input text field to reference the JS function







Solution 2:
- Generate RowImpl java class on EmployeView View Object by double clicking go to Java tab press the pencil icon on the top right and check the options.

- Change value to value.ToUpperCase() in the method of setLastName as shown in the slide

- Set AutoSubmit to TRUE of LastName field in JSF page


Run the application Enter "steve" in the First Name field and tab out you will notice it will automatically convert to "STEVE" do the same for Last Name enter "king" and tab out it will convert to "KING"

Download the example workspace

Happy JDeveloping,
Baig

Sunday, June 6, 2010

Deleting multi-selected rows from adf table

Hi all,

Back from little trip from Karachi and today i will show how to delete multiple selected rows from adf table.

In this example i will selected rows using
1)  CTRL or SHIFT with mouse click
2)  Checkbox at the row
and press Delete button for ease of understanding i created 2 separate buttons in the examples.

Before start i assumed you already setup a Application with EO,VO and AM also using HR Connection

- Add a Transient Attribute to VO of Boolean type named "SelectedRow" We will use this to select row
Here the layout looks like



- Drag a Collection from DataControl as ADF Table to JSF page
- Dont Check RowSelection Checkbox
- Set the table RowSelection property to multiple
- Set EditingMode property to clickToEdit
- Surround your table with af:PanelCollection for look and feel give table a id "myTab"
- Add a toolbar in toolbar facet of Panelcollection
- Add 2 toolbar buttons to your toolbar
- Add partial triggers to your table reference both buttons on toolbar
- Create a backing bean
- Add a RichTable object to your bean with getter and setter methods.
- Set the binding property of the af:table to your Managed Bean
- Add Methods in Backing bean similar to the following code
- Link a method deleteAction to your "Delete Selected Rows" button and DeleteCheckedRows to other button.

Download example for more info

Note: Don't forget to commit your rows after delete :)

More Reading:
- Providing Multiselect capabilities Fusion developer guide

-How to add Transient Checkbox to Table A good example can also be found here
http://sameh-nassar.blogspot.com/2009/12/use-checkbox-for-selecting-multiple.html
http://baigsorcl.blogspot.com/2010/05/adding-boolean-checkbox-to-table.html

Processing on multi Rows another example from Mr.Steve Muench

Happy JDeveloping,
Baig

Thursday, June 3, 2010

Vote for my ADF Proposals for Oracle Open World 2010

Hi all,

As i read the Mr.Shay blog post about the last chance to submit the Jdev/ADF sessions for OOW i have also submitted 3 proposals Please Vote for it :) 

You need Oracle MIX account for it


1) Performing Common Oracle Forms Tasks in Oracle ADF
 Learn how to perform Common Oracle Forms tasks (POST-QUERY, Triggers, Validations, canvases etc etc) in Oracle ADF majority of this session would be demonstration with few little slides and tips on migration from Oracle Forms to ADF.
This session would be helpful for people who are coming from Oracle forms background and want to move to Oracle ADF.

2) Challenges to Face while Migrating Forms to ADF 
 Is Oracle Forms dead? We have years of investment in Oracle forms how to protect that? Moving to ADF means major part of the code requires re-write? This session will provide answers to all questions. The purpose of this session is to how to protect your existing Forms investment by Integrating with SOA technology as well as the Challenges to face while migrating Oracle Forms application to ADF.
This session would be combination of slides and demonstration.

3) Development in Oracle ADF Design to Deployment
This Session will describe the whole process of designing, developing and deploying applications in Oracle ADF using Jdeveloper 11g by taking a Case study application.
This session is based on 90% on demonstration and will explain some basics about ADF components.


Best Regards,
Zeeshan Baig