Skip to content
November 28, 2012 / Pedro Gabriel

Communication Between Regions without Contextual Events

In most cases making use of Contextual Events in order to gather and send information between ADF regions may become hard to reach what we really want to achieve. In order to overcome this situation, today we will demonstrate how to accomplish ADF Regions’ communication by using ADF default out of the box functionalities.

You can download two slightly different versions of this example here: CommunicationBetweenRegions1, CommunicationBetweenRegions2.

For this example we created three regions, one we called “ParentsRegion” which gathers and publish information from/to the other two regions (“Region A” and “Region B”). The first step is to create ADF Task Flows, one for each region:

Then create the “Managed Beans” for each new ADF Task Flow. In “ParentsRegion” managed bean create new global variables to reference “RegionA” and “RegionB” managed beans. In “RegionA” and “RegionB” make the same but this time to reference “ParentsRegion” managed Bean. The “initFlow” method in “RegionA” and “RegionB” initializes the parent’s region variable. This double reference will allow you to gather and publish information between regions.

package CommunicationBetweenRegions;
import Common.Utils;
import javax.faces.event.ActionEvent;
import oracle.adf.view.rich.component.rich.output.RichOutputText;

public class ParentsRegion {

    private RegionA regionA;
    private RegionB regionB;

    private String yourName;
    private RichOutputText outputTextYourName;

    public void setRegionA(RegionA regionA) {
        this.regionA = regionA;
    }

    public RegionA getRegionA() {
        return regionA;
    }

    public void setRegionB(RegionB regionB) {
        this.regionB = regionB;
    }

    public RegionB getRegionB() {
        return regionB;
    }

    public void commandButtonClean(ActionEvent actionEvent) {
        yourName = null;
        regionA.cleanFirstName();
        regionB.cleanLastName();
    }

    public void commandButtonSubmit(ActionEvent actionEvent) {
        yourName = regionA.getFirstName() + " " + regionB.getLastName();
        Utils.refreshComponent(outputTextYourName);
    }

    public void setYourName(String yourName) {
        this.yourName = yourName;
    }

    public String getYourName() {
        return yourName;
    }

    public void setOutputTextYourName(RichOutputText outputTextYourName) {
        this.outputTextYourName = outputTextYourName;
    }

    public RichOutputText getOutputTextYourName() {
        return outputTextYourName;
    }
}

 

package CommunicationBetweenRegions;

import Common.Utils;

import oracle.adf.view.rich.component.rich.input.RichInputText;

public class RegionA {

    private ParentsRegion parentsRegionManagedBean;

    private String firstName = "";
    private RichInputText inputText_RegionA;

    public void initFlow() {
        this.parentsRegionManagedBean.setRegionA(this);
    }

    public void setParentsRegionManagedBean(ParentsRegion parentsRegionManagedBean) {
        this.parentsRegionManagedBean = parentsRegionManagedBean;
    }

    public ParentsRegion getParentsRegionManagedBean() {
        return parentsRegionManagedBean;
    }

    public void cleanFirstName() {
        this.firstName = "";
        Utils.refreshComponent(inputText_RegionA);
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setInputText_RegionA(RichInputText inputText_RegionA) {
        this.inputText_RegionA = inputText_RegionA;
    }

    public RichInputText getInputText_RegionA() {
        return inputText_RegionA;
    }
}

 

package CommunicationBetweenRegions;

import Common.Utils;

import oracle.adf.view.rich.component.rich.input.RichInputText;

public class RegionB {

    private ParentsRegion parentsRegionManagedBean;

    private String lastName = "";
    private RichInputText inputText_LastName;

    public void initFlow() {
        this.parentsRegionManagedBean.setRegionB(this);
    }

    public void setParentsRegionManagedBean(ParentsRegion parentsRegionManagedBean) {
        this.parentsRegionManagedBean = parentsRegionManagedBean;
    }

    public ParentsRegion getParentsRegionManagedBean() {
        return parentsRegionManagedBean;
    }

    public void cleanLastName() {
        this.lastName = "";
        Utils.refreshComponent(inputText_LastName);
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setInputText_LastName(RichInputText inputText_LastName) {
        this.inputText_LastName = inputText_LastName;
    }

    public RichInputText getInputText_LastName() {
        return inputText_LastName;
    }
}

Next you need to set “RegionA” and “RegionB” ADF Task Flow parameters based on previously created global variables.

Then create the page fragments, drag and drop “RegionA” and” RegionB” into “ParentsRegion” and finally define the input parameters for both regions as shown:

Now at runtime you can gather and clean the information on “RegionA” and “RegionB” while you click on “ParentsRegion” buttons.

Pedro Gabriel

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: