Saturday, March 19, 2011

Region Interaction Example 1


Imagine you have a table (based on Department) and a region containing a table ( Based on Employees as shown in the image below ), and you want to sync up Employee Region based on the row selected on Departments 1.


To avoid empty space, added the following for each of the table:
1. Set the content delivery as immediate.
2. Set the AutoHeightRows to VO's rangeSize attribute, eg. #{bindings.DeptVO1.rangeSize}.

Constraint:
1. There is no relation/connection between the data model of the first and the second region. EMP and DEPT table are totally independent as shown by the following SQLs:

CREATE TABLE DEPT (
  dept_id   NUMBER(10,0) PRIMARY KEY,
  dept_name VARCHAR2(50) NULL
);

INSERT INTO DEPT VALUES ( 1, 'Finance');
INSERT INTO DEPT VALUES ( 2, 'Sales'); 
INSERT INTO DEPT VALUES ( 3, 'Human Resource'); 
INSERT INTO DEPT VALUES ( 4, 'BPO'); 
INSERT INTO DEPT VALUES ( 5, 'SCM');

CREATE TABLE EMP (
  emp_id   NUMBER(10,0) PRIMARY KEY,
  emp_name VARCHAR2(50) NULL,
  dept_id  NUMBER(10,0) NULL
);

INSERT INTO EMP VALUES ( 1, 'Emp 1', 1);
INSERT INTO EMP VALUES ( 2, 'Emp 2', 2);
INSERT INTO EMP VALUES ( 3, 'Emp 3', 3);
INSERT INTO EMP VALUES ( 4, 'Emp 4', 4);
INSERT INTO EMP VALUES ( 5, 'Emp 5', 5);
INSERT INTO EMP VALUES ( 6, 'Emp 6', 1);
INSERT INTO EMP VALUES ( 7, 'Emp 7', 2);
INSERT INTO EMP VALUES ( 8, 'Emp 8', 3);
INSERT INTO EMP VALUES ( 9, 'Emp 9', 4);
INSERT INTO EMP VALUES ( 10, 'Emp 10', 5);

2. The region ( or the task flow ) takes an input parameter as Department Id.
3. The task flow first have method activity as a default activity that executes the EmpVO based on the department ID provided. It then transfers the control to the view activity that contains the employees table.

Problem:
You want to sync up Employee Region based on the row selected on Departments table, as shown in below images:


And



Solution:
1. Expose the Department ID of the Department table as an attribute binding.
2. Pass the 1 attribute binding input value as the parameter to the task flow binding, eg #{bindings.DeptId.inputValue}.
3. Set the refresh property of the task flow binding as 'ifNeeded'.
4. Set the partial trigger of second region to refer table 1

Here is the code snippet for the page ( that contains the table and task flow region):
<?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:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1" binding="#{backingBeanScope.backing_untitled2.d1}">
      <af:messages binding="#{backingBeanScope.backing_untitled2.m1}" id="m1"/>
      <af:form id="f1" binding="#{backingBeanScope.backing_untitled2.f1}">
        <af:table value="#{bindings.DeptVO1.collectionModel}" var="row"
                  rows="#{bindings.DeptVO1.rangeSize}"
                  emptyText="#{bindings.DeptVO1.viewable ? 'No data to display.' : 'Access Denied.'}"
                  fetchSize="#{bindings.DeptVO1.rangeSize}"
                  rowBandingInterval="0"
                  selectedRowKeys="#{bindings.DeptVO1.collectionModel.selectedRow}"
                  selectionListener="#{bindings.DeptVO1.collectionModel.makeCurrent}"
                  rowSelection="single"
                  binding="#{backingBeanScope.backing_untitled2.t1}" id="t1"
                  contentDelivery="immediate"
                  autoHeightRows="#{bindings.DeptVO1.rangeSize}"
                  columnStretching="last">
          <af:column sortProperty="DeptId" sortable="false"
                     headerText="#{bindings.DeptVO1.hints.DeptId.label}"
                     id="c1">
            <af:outputText value="#{row.DeptId}" id="ot1">
              <af:convertNumber groupingUsed="false"
                                pattern="#{bindings.DeptVO1.hints.DeptId.format}"/>
            </af:outputText>
          </af:column>
          <af:column sortProperty="DeptName" sortable="false"
                     headerText="#{bindings.DeptVO1.hints.DeptName.label}"
                     id="c2">
            <af:outputText value="#{row.DeptName}" id="ot2"/>
          </af:column>
        </af:table>
        <af:spacer width="10" height="10"
                   binding="#{backingBeanScope.backing_untitled2.s1}" id="s1"/>
        <af:region value="#{bindings.EmpVOExecutionTaskFlow1.regionModel}"
                   id="r1" binding="#{backingBeanScope.backing_untitled2.r1}"
                   partialTriggers="::t1"/>
      </af:form>
    </af:document>
  </f:view>
  <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_untitled2-->
</jsp:root>

And here comes its page definition file:

<?xml version="1.0" encoding="UTF-8" ?>
<pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel"
                version="11.1.1.59.23" id="untitled1PageDef"
                Package="view.pageDefs">
  <parameters/>
  <executables>
    <variableIterator id="variables"/>
    <iterator Binds="DeptVO1" RangeSize="25" DataControl="AppModuleDataControl"
              id="DeptVO1Iterator"/>
    <taskFlow id="EmpVOExecutionTaskFlow1"
              taskFlowId="/WEB-INF/EmpVOExecutionTaskFlow.xml#EmpVOExecutionTaskFlow"
              activation="deferred"
              xmlns="http://xmlns.oracle.com/adf/controller/binding"
              Refresh="ifNeeded">
      <parameters>
        <parameter id="deptId" value="#{bindings.DeptId.inputValue}"/>
      </parameters>
    </taskFlow>
  </executables>
  <bindings>
    <tree IterBinding="DeptVO1Iterator" id="DeptVO1">
      <nodeDefinition DefName="model.DeptVO" Name="DeptVO10">
        <AttrNames>
          <Item Value="DeptId"/>
          <Item Value="DeptName"/>
        </AttrNames>
      </nodeDefinition>
    </tree>
    <attributeValues IterBinding="DeptVO1Iterator" id="DeptId">
      <AttrNames>
        <Item Value="DeptId"/>
      </AttrNames>
    </attributeValues>

  </bindings>
</pageDefinition>

Here is the task flow (embedded as a region specified earlier ) code snippet:

<?xml version="1.0" encoding="windows-1252" ?>
<adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
  <task-flow-definition id="EmpVOExecutionTaskFlow">
    <default-activity id="__4">executeEmpVO</default-activity>
    <input-parameter-definition id="__2">
      <name id="__1">deptId</name>
      <value>#{pageFlowScope.deptIdDef}</value>
      <class>oracle.jbo.domain.Number</class>
      <required/>
    </input-parameter-definition>
    <managed-bean id="__8">
      <managed-bean-name id="__5">backing_EmpView</managed-bean-name>
      <managed-bean-class id="__7">view.backing.EmpView</managed-bean-class>
      <managed-bean-scope id="__6">backingBean</managed-bean-scope>
      <!--oracle-jdev-comment:managed-bean-jsp-link:1EmpView.jsff-->
    </managed-bean>
    <view id="EmpView.jsff">
      <page>/EmpView.jsff</page>
    </view>
    <method-call id="executeEmpVO">
      <method>#{bindings.executeEmpVO.execute}</method>
      <outcome id="__3">
        <fixed-outcome>executeEmpVO</fixed-outcome>
      </outcome>
    </method-call>
    <control-flow-rule id="__9">
      <from-activity-id id="__10">executeEmpVO</from-activity-id>
      <control-flow-case id="__13">
        <to-activity-id id="__12">EmpView.jsff</to-activity-id>
      </control-flow-case>
    </control-flow-rule>
    <use-page-fragments/>
  </task-flow-definition>
</adfc-config>

And here is the code of the Application Module that exposes executeEmpVO as a Client Interface method.

package model;
import model.common.AppModule;
import oracle.jbo.ViewObject;
import oracle.jbo.server.ApplicationModuleImpl;
import oracle.jbo.server.ViewObjectImpl;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Sat Mar 19 20:43:03 IST 2011
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class AppModuleImpl extends ApplicationModuleImpl implements AppModule {
    /**
     * This is the default constructor (do not remove).
     */
    public AppModuleImpl() {
    }
    /**
     * Container's getter for EmpVO1.
     * @return EmpVO1
     */
    public ViewObjectImpl getEmpVO1() {
        return (ViewObjectImpl)findViewObject("EmpVO1");
    }
    /**
     * Container's getter for DeptVO1.
     * @return DeptVO1
     */
    public ViewObjectImpl getDeptVO1() {
        return (ViewObjectImpl)findViewObject("DeptVO1");
    }
   
    public void executeEmpVO(oracle.jbo.domain.Number deptId){
      ViewObject vo = this.getEmpVO1();
      // Set the two design time named bind variables
      vo.setWhereClause("dept_id = :TheDeptId");
      vo.defineNamedWhereClauseParam("TheDeptId", null, null);
      vo.setNamedWhereClauseParam("TheDeptId", deptId);
      vo.executeQuery();
    }

}

Thats it.

JDev Release 11.1.1.4

No comments:

Post a Comment