Sunday, September 29, 2013

ADF Page to render Unknown Number of Regions


Create two task flows

Task Flow 1:


dyregion_view1.jsff

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Region 1" id="ot1"/>
  </af:panelGroupLayout>

</jsp:root>

Task Flow 2:
dynamicRegion_view2.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Region 2" id="ot1"/>
  </af:panelGroupLayout>

</jsp:root>

Create the managed bean in the pageFlowScope. The code for the managed bean is as below
package view;

import java.util.ArrayList;
import java.util.List;

import oracle.adf.controller.TaskFlowId;
import oracle.adf.controller.binding.TaskFlowBindingAttributes;

public class MultiBean {
  
   private List<TaskFlowBindingAttributes> mattrs= new ArrayList<TaskFlowBindingAttributes>(5);
   public MultiBean() {
      
       TaskFlowBindingAttributes tfAttr= new TaskFlowBindingAttributes();
       tfAttr.setId("region1");
       tfAttr.setTaskFlowId(new TaskFlowId("/WEB-INF/tfDynamicRegion.xml","tfDynamicRegion"));
       mattrs.add(tfAttr);
      
       tfAttr= new TaskFlowBindingAttributes();
       tfAttr.setId("region2");
       tfAttr.setTaskFlowId(new TaskFlowId("/WEB-INF/tfDyanamicRegion1.xml","tfDyanamicRegion1"));
       mattrs.add(tfAttr);
   }
   public List<TaskFlowBindingAttributes> getTaskFlowList() {
       return mattrs;
   }
  

}

Create a test page and go to the pageDef of the page. Add Executables as below

Click on OK to go the screen below and enter the values as shown.

Create the test page
testMultiFlow.jspx
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="testMultiFlow.jspx" id="d1">
            <af:form id="f1">
                <af:panelGroupLayout id="pgl1">
             
                    <af:panelTabbed id="pt1">
                    <af:forEach items="#{bindings.multiId.taskFlowBindingList}" var="regs">
                   
                        <af:showDetailItem text="#{regs.name}" id="sdi1">
                                <af:panelBox text="#{regs.name}" id="pb2">
                                    <f:facet name="toolbar">
                                     <af:region value="#{regs.regionModel}" id="r2"/>
                                    </f:facet>
                                </af:panelBox>
                            </af:showDetailItem>
                        </af:forEach>
                    </af:panelTabbed>
                </af:panelGroupLayout>
            </af:form>
        </af:document>
    </f:view>

</jsp:root>

Run and see the two region displayed in the showdetailItems of the Tabed layout.

ADF Dynamic Region

Create two bounded task flows

Task Flow1 :

dyregion_view1.jsff

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Region 1" id="ot1"/>
  </af:panelGroupLayout>

</jsp:root>

Task Flow2 :
dynamicRegion_view2.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Region 2" id="ot1"/>
  </af:panelGroupLayout>

</jsp:root>

Drag and drop the first task flow as Dynamic Region

Create Managed bean for Region Binding as below


Code for the TestBean.java
package view;

import oracle.adf.controller.TaskFlowId;

public class TestBean {
    private String taskFlowId = "/WEB-INF/tfDynamicRegion.xml#tfDynamicRegion";

    public TestBean() {
        System.out.println("taskFlowId=" + taskFlowId);
    }

    public String test() {
        taskFlowId = "/WEB-INF/tfDyanamicRegion1.xml#tfDyanamicRegion1";
        System.out.println("taskFlowId1 =" + taskFlowId);
        // Add event code here...
        return null;
    }

    public TaskFlowId getDynamicTaskFlowId() {
        return TaskFlowId.parse(taskFlowId);
    }

    public void setDynamicTaskFlowId(String taskFlowId) {
        this.taskFlowId = taskFlowId;
    }

    public String test1() {
        // Add event code here...
        taskFlowId = "/WEB-INF/tfDynamicRegion.xml#tfDynamicRegion";
        System.out.println("taskFlowId2=" + taskFlowId);
        return null;
    }

}

Create a testDynamicRegion.jspx as below 
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="testDynamicRegion.jspx" id="d1">
            <af:form id="f1">
                <af:panelGroupLayout id="pgl1">
                    <af:link text="link 1" id="l1" action="#{pageFlowScope.TestBean.test1}"/>
                    <af:link text="link 2" id="l2" action="#{pageFlowScope.TestBean.test}"/>
                </af:panelGroupLayout>
                <af:region value="#{bindings.dynamicRegion1.regionModel}" id="r1"/>
            </af:form>
        </af:document>
    </f:view>

</jsp:root>

Run the pages and click on the pages to see the region dynamically changes.

Saturday, September 28, 2013

Navigating outside the region using Parent Action

Create a page Home.jspx as a view activity of adfc-config.xml
Create a bounded task flow using parent action activity
Parent action has the following properties
Parent Outcome - For parent action activity to navigate to the parent view activity
Root Outcome - For parent action activity to navigate to a the root page of the application
Activation_view1.jspx
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Region jsff" id="ot1"/>
    <af:button text="button 1" id="b1" action="toParent"/>
  </af:panelGroupLayout>

</jsp:root>

Click on the button it will go to the goHome flow defined in adfc-config.

Sunday, September 22, 2013

Refreshing ADF region


  • We can configure region, refreshes to invoke the task flow 
  • ADF region can invoke the task flow if the region is in active state 

There are two type of refresh options
1) Default - Refreshes the region when the page loads and RefreshCondition=true.
2) ifNeeded - Refreshes the region if the value of the flow binding parameters changes.ifNeeded Option is set do not set the refresh condition

Shown above are the activation options for a region

Conditional -Refreshes the region if true
Differed - This is relevant if the the applications uses Faceletes XHTML pages
Immediate - Refresh the region immediately.Region refresh when the page displays

There are 3 ways of refreshing the region

1) Neither refresh or RefreshCondition specified ,Region refreshes the parent page displays
2) ADF region get refreshes when the RefreshConditions EL returns true .Refresh condition is independent of the changing value of binding parameters
3) ifNeeded is set for the Refresh option.Any change of value of binding parameters the refresh take place.ifNeeded selected no RefreshCondition specified.

Lets go through an example demonstrating the refresh condition
Create a task flow
Create a managed bean in pageflowscope of the task flow.

package view;

import java.util.HashMap;
import java.util.Map;

import oracle.adf.view.rich.context.AdfFacesContext;

public class RegionMap {
    private boolean refresh;
    private String time;

    public void setTime(String time) {
        this.time = time;
    }

    public void setRefresh(boolean refresh) {
        this.refresh = refresh;
    }

    public boolean isRefresh() {

        String flag =(String) AdfFacesContext.getCurrentInstance().getPageFlowScope().get("varFlag");
     
        if ("true".equals(flag))
            return true;
        else
            return false;

    }

    public RegionMap() {
        super();
    }

    public Map getMyMap() {
        Map map = new HashMap();
        map.put("test1", "test1");
        map.put("test2", "test2");
        return map;
    }

    public String getTime() {
        long t =System.currentTimeMillis();
        System.out.println(t);
        return "" + t;
    }

    public boolean refreshRegion() {

        AdfFacesContext.getCurrentInstance().getPageFlowScope().put("curTime", System.currentTimeMillis());
        return true;
    }

    public String testMeth() {
        String flag=("true".equals((String) AdfFacesContext.getCurrentInstance().getPageFlowScope().get("varFlag")) ? "false" :
         "true");
        AdfFacesContext.getCurrentInstance().getPageFlowScope().put("varFlag", flag);
        System.out.println("Flag =" + flag);
        // Add event code here...
        return null;
    }
}

 Drag and drop the task flow to testRefreshRegion.jspx as a region and set the refresh condition as shown below

The code for testRefreshRegion.jspx is as below :
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="testRefreshRegion.jspx" id="d1">
            <af:form id="f1">
                <af:region value="#{bindings.regionRefresh1.regionModel}" id="r1"/>
                <af:button text="button 1" id="b1" action="#{pageFlowScope.RegionMap.testMeth}"/>
            </af:form>
        </af:document>
    </f:view>

</jsp:root>

We need to add the managed bean to adfc-config.xml to visible to this page.Run the page. Click on the button based on the pageFlowScope variable = true the region will get refreshed.

ifNeeded and Binding variable change 

 Change the refresh property to ifNeeded as below .


Code for the testRefreshRegion.jspx is as below 

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="testRefreshRegion.jspx" id="d1">
            <af:form id="f1">
                <af:region value="#{bindings.regionRefresh1.regionModel}" id="r1"/>
                <af:button text="button 1" id="b1" action="#{pageFlowScope.RegionMap.testMeth}"/>
                <af:button text="button 2" id="b2" action="#{pageFlowScope.RegionMap.testChange}"/>
            </af:form>
        </af:document>
    </f:view>
Added button 2 here with action method as #{pageFlowScope.RegionMap.testChange}

Add testChange() method to the managed bean.
    public String testChange() {
        AdfFacesContext.getCurrentInstance().getPageFlowScope().put("changeVar", getTime());
       
        // Add event code here...
        return null;
    }


Go to the page Def file of the testRefreshRegionPage.jspx and add parameters there .

<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="12.1.2.66.68" id="testRefreshRegionPageDef"
                Package="view.pageDefs">
  <parameters/>
  <executables>
    <variableIterator id="variables"/>
    <taskFlow id="regionRefresh1" taskFlowId="/WEB-INF/regionRefresh.xml#regionRefresh" activation="deferred"
              xmlns="http://xmlns.oracle.com/adf/controller/binding" Refresh="ifNeeded">
      <parameters>
        <parameter id="parameter" value="#{pageFlowScope.changeVar}"/>
      </parameters>
    </taskFlow>
  </executables>
  <bindings/>
</pageDefinition>

Run the page and click on the 2nd button to see the region refreshes .

Passing Parameters to Region using Parameter Map


  • We can pass parameters to region using parameter property of the region.
  • Parameter Map object is of java.util.Map
  • ADF region or ADF dynamic region can use parameter map 
  • Parameter Map reduces number of parameters under bindings in the page def file of the jspx file where we are dropping the task flow as region.
  • If there are same parameters in the binding and the map the map take the precedence 


Create a bounded task flow
Added two input parameters to the bounded task flow test1 and test2. Drag and drop the task flow to the testParamMapToRegion.jspx. Code for the testParamMapToRegion.jspx is as shown below:
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
        <af:document title="testParamMapToRegion.jspx" id="d1">
            <af:form id="f1">
                <af:region value="#{bindings.parameterMaptoRegion1.regionModel}" id="r1"/>
            </af:form>
        </af:document>
    </f:view>

</jsp:root>

Create a managed bean with pageflowScope in adfc-config.xml 

package view;

import java.util.HashMap;
import java.util.Map;

public class RegionMap {
    public RegionMap() {
        super();
    }

    public Map getMyMap() {
        Map map = new HashMap();
       // Parameter value is set here.
        map.put("test1", "test1");
        map.put("test2", "test2");
        return map;
    }
}

The code for the map_view1.jspx is as shown below :

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value=" Test =#{pageFlowScope.test1}" id="ot1"/>
     <af:outputText value=" Test =#{pageFlowScope.test2}" id="ot2"/>
  </af:panelGroupLayout>

</jsp:root>

Run the testParamMapToRegion.jspx page and see the pageFlowScope parameters test1 and test2.

Saturday, September 14, 2013

Page Fragment and View Port


  • Page fragments .jsff renders content in another jsf page 
  • Page fragment should not have more than one root element 
  • Page Fragment should not have af:document,f:view,f:form,head,body elements 
  • Bounded task flow add to jsf page as region should have page fragments only 


<?xml version='1.0' encoding='UTF-8'?>

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"></jsp:root>

  • View port is the display area capable of navigating independently of other view ports ,region or browser window 
  • We can set security on bounded task flow displayed over region 

ADF Region with parameter

We can execute a bounded task flow with page or jsff fragment using ADF region.ADF region helps in re-usability of the code.ADF region consists of a af:region and the instance object is of oracle.adf.view.rich.model.RegionModel .On first rendering the ADF region content is the first view activity in the bounded task flow.taskflow in the page binding identifies the bounded task flow uses region.mulitaskFlow identifies list of bounded task flow uses region.We can pass values to region using input parameters or using contextual events .parameterMap is an object of java.util.Map identifies what input parameters the task flow passes from task flow to region.Dynamic region is the region what bounded task flow to render on runtime.

Create a bounded task flow with input parameter
region_view1.jsff

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Input = #{pageFlowScope.inputParameter1}" id="ot1"/>
  </af:panelGroupLayout>

</jsp:root>

Drag and drop the bounded task flow as region 

Edit the page definition of the test page and pass the parameter either through value or EL expression.
Page definition file of the test page.

<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="12.1.2.66.68" id="testRegionPageDef"
                Package="view.pageDefs">
  <parameters/>
  <executables>
    <variableIterator id="variables"/>
    <taskFlow id="btfadfregion1" taskFlowId="/WEB-INF/btf-adf-region.xml#btf-adf-region" activation="deferred"
              xmlns="http://xmlns.oracle.com/adf/controller/binding">
      <parameters>
        <parameter id="inputParameter1" value="Testing"/>
      </parameters>
    </taskFlow>
  </executables>
  <bindings/>
</pageDefinition>

The code for region_view1.jsff 

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:outputText value="Input = #{pageFlowScope.inputParameter1}" id="ot1"/>
  </af:panelGroupLayout>
</jsp:root>


Run the page and see the input parameter from the region_view1.jsff 

Saturday, September 7, 2013

Return Value For Bounded Task Flow

Bounded task flow can return a value.Task Flow call activity return value by reference.
Create a task flow that is called as below :

Also see the return value specified

Outcome of the task flow return activity is taskFlowReturn1.
return_called_view1.jsff
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:button text="button 1" id="b1" action="toView2"/>
  </af:panelGroupLayout>

</jsp:root>
Calling Task Flow is as below 


See the return value specified coming over to the task flow call activity.
return_calling_view1.jsff 
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1">
    <af:button text="button 1" id="b1" action="toTFCall"/>
  </af:panelGroupLayout>
</jsp:root>
return_calling_view2.jsff 
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <af:panelGroupLayout id="pgl1"/>
  <af:outputText value="test- #{pageFlowScope.retVal1}" id="ot1"/>
</jsp:root>
Click on button and finally see the "Hello World" printed.

Code snippet for the calling task flow 
<task-flow-call id="return_called_tf">
      <task-flow-reference>
        <document>/WEB-INF/return_called_tf.xml</document>
        <id>return_called_tf</id>
      </task-flow-reference>
      <return-value id="__1">
        <name>returnValue1</name>
        <value>#{pageFlowScope.retVal1}</value>
      </return-value>
    </task-flow-call>

Code snippet for the called task flow 

  <task-flow-definition id="return_called_tf">
    <default-activity>return_called_view1</default-activity>
    <return-value-definition id="__1">
      <name>returnValue1</name>
      <value>Hello World</value>
      <class>java.lang.String</class>
    </return-value-definition>