Sunday, September 28, 2014

BPEL 1.1: While Activity & Traverse through Collection

Following topic will help you to understand one of BPEL Advanced activities 'While' usage & how to traverse/iterate through data collection.

1. Create two variables in your BPEL as mentioned below.

    <variable name="Counter" type="xsd:int"/>
    <variable name="Nodes" type="xsd:int"/>

2. Add Assign activity to flow.

>  set Counter variable value to 1 &
>  count the number of nodes in data collection and assign to Nodes variable
 
    <assign name="InitializeVariables">
      <copy>
        <from expression="1"/>
        <to variable="Counter"/>
      </copy>
      <copy>
        <from expression="ora:countNodes('InputVariable','EmpCollection','/ns2:EmpCollection/ns2:Emp')"/>
        <to variable="Nodes"/>
      </copy>
    </assign>

Note: Typically use the expression builder to identify the element then replace the bpws:getVariableData with ora:countNodes.

3. Add While activity and specify condition as needed.

   condition="bpws:getVariableData('Counter') &lt;= bpws:getVariableData('Nodes')"
 
4. Access record at particular index in the array using []. Specify Counter variable to iterate through each record in collection.

    /ns2:EmpCollection/ns2:Emp[bpws:getVariableData('Counter')]/ns2:empId

5. Increment Counter in the end. Sample While Activity block provided below.

    <while name="WhileMultiNodes"
           condition="bpws:getVariableData('Counter') &lt;= bpws:getVariableData('Nodes')">
      <sequence name="Sequence">
        <assign name="AssignValue">
          <copy>
            <from variable="InputVariable"
                  part="EmpCollection"
                  query="/ns2:EmpCollection/ns2:Emp[bpws:getVariableData('Counter')]/ns2:empId"/>
            <to variable="empID"/>
          </copy>
        </assign>
        <assign name="IncrementCounter">
          <copy>
            <from expression="bpws:getVariableData('Counter') + 1"/>
            <to variable="Counter"/>
          </copy>
        </assign>
      </sequence>
    </while>

ADF: Export only Selected Rows from Table

Following post helps you to export only selected rows from ADF table.

We all know that af:exportCollectionActionListener operation allows to export rows from ADF table. by default it exports all the rows exists in the table.

Default af:exportCollectionActionListener usage:

  <af:commandButton text="Export Rows" id="cb1">
          <af:exportCollectionActionListener exportedId="t1"   -- t1 refers to ID for the ADF table
                                                               type="excelHTML"
                                                               filename="exportedRows.xls"/>
  </af:commandButton>

If you want to export the selected rows only from ADF table,  af:exportCollectionActionListener tag contains another attribute named exportedRows.

exportedRows --> valid values 'all' or 'selected'have to modify our above code as shown below.

  <af:commandButton text="Export Selected Rows" id="cb1">
          <af:exportCollectionActionListener exportedId="t1"
                                                               type="excelHTML"
                                                               filename="exportedRows.xls"
                                                               exportedRows="selected"/>
  </af:commandButton>