Pages - Menu

Sunday, September 15, 2013

Unified - General DML/Navigation Back Bean | Oracle ADF

Hi,
While Leading Oracle Fusion Discussion Group B Team - Saudi Arabia / Gulf Area, i decided to change & Enhance my General Mechanism for DML operations to be more simple, Unified & General for my ADF Applications.
today, i show a new way to make your DML operations/ Records Navigation  are easy to handle & Managed for all your team and make it more easy to be customizable by any of your Developers & for any purpose.
idea “is to make your Action Sources - Buttons or whatever you use to pass Iterators Names or Defined Page Definition Actions” with Action or Action Listeners methods”.
Benefits.
  • One Managed/Back Bean Easy to Handle (Request Scope).
  • Customizable for any special commit & RollBack Behavior.
  • General For any Iterator, Actions & for any page.
First of all, you have to build one small ADF/JSF application and in your task flow by adding it in Adfc-config.xml or faces-config.xml as you work.
  <managed-bean>
    <managed-bean-name>dml</managed-bean-name>
    <managed-bean-class>Beans.dml</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>


package Beans;

import WA.WABEAN;
import javax.faces.event.ActionEvent;
import oracle.adf.view.rich.component.rich.RichPopup;
import oracle.binding.OperationBinding;
import oracle.jbo.DMLException;
import oracle.jbo.Row;
import oracle.jbo.RowSetIterator;

public class dml {

    WABEAN mybean = new WABEAN();
    private String MethodNameorIteratorBinding = “”;
    private RichPopup p2;
    private RichPopup p3;

    public String CreateInsert() {
        if (getMethodNameorIteratorBinding() != null) {
            RowSetIterator Schedual =
           mybean.AccessIteratorBinding(getMethodNameorIteratorBinding()).getRowSetIterator();
            Row lastRow = Schedual.last();
            int lastRowIndex = Schedual.getRangeIndexOf(lastRow);
            Row newRow = Schedual.createRow();
            newRow.setNewRowState(Row.STATUS_INITIALIZED);
            Schedual.insertRowAtRangeIndex(lastRowIndex + 1, newRow);
            Schedual.setCurrentRow(newRow);
        }
        return null;
    }
    public String Delete() {
        if (getMethodNameorIteratorBinding() != null) {
            mybean.AccessOperation(getMethodNameorIteratorBinding()).execute();
        }
        return null;
    }
    public String Next() {
        if (getMethodNameorIteratorBinding() != null) {
            mybean.AccessOperation(getMethodNameorIteratorBinding()).execute();
        }
        return null;
    }
    public String Previous() {
        if (getMethodNameorIteratorBinding() != null) {
            mybean.AccessOperation(getMethodNameorIteratorBinding()).execute();
        }
        return null;
    }
    public void Commit(ActionEvent actionevent) {
        if (getMethodNameorIteratorBinding() != null) {
            try {
                OperationBinding commit = mybean.AccessOperation(getMethodNameorIteratorBinding());
                commit.execute();
                if (commit.getErrors().isEmpty()) {
                    mybean.ShowDialog(getP2(), actionevent);
                }
            } catch (DMLException e) {
                mybean.Validate(mybean.getFacesContext(), “Commit ..”, e.getErrorCode() + ” - ” + e.getBaseMessage(),
                                1);
            }
        }
    }
    public void Rollback(ActionEvent actionevent) {
        if (getMethodNameorIteratorBinding() != null) {
            try {
                OperationBinding rollback = mybean.AccessOperation(getMethodNameorIteratorBinding());
                rollback.execute();
                if (rollback.getErrors().isEmpty()) {
                    mybean.ShowDialog(getP3(), actionevent);
                }
            } catch (DMLException e) {
                mybean.Validate(mybean.getFacesContext(), “RollBack ..”, e.getErrorCode() + ” - ” + e.getBaseMessage(),
                                1);
            }
        }
    }
    public void setMethodNameorIteratorBinding(String MethodNameorIteratorBinding) {
        this.MethodNameorIteratorBinding = MethodNameorIteratorBinding;
    }
    public String getMethodNameorIteratorBinding() {
        return MethodNameorIteratorBinding;
    }
    public void setP2(RichPopup p2) {
        this.p2 = p2;
    }
    public RichPopup getP2() {
        return p2;
    }
    public void setP3(RichPopup p3) {
        this.p3 = p3;
    }
    public RichPopup getP3() {
        return p3;
    }
}
Before Continue, please Note,
  • Create Insert method insert record for next row index (Require Iterator Name) and no need for action.
  • Delete, Next & Previous (Required Actions Names Defined in Page Definitions).
  • Commit & Rollback Methods make it’s purposes and Handle Errors Expected and Show Feedback Dialogs as well.
  • MethodNameorIteratorBinding used to pass Iterator or Actions Names Required
Finally, build your jsf, jspx or jsff page and make toolbar containing the buttons of 6 dml operations (insert, delete, next record, previous record, commit & rollback) and add the “setPropertyListener” passing Iterators or Actions Required.
                <af:toolbar id=”t1”>
                  <af:button id=”b1” icon=”#{resource[‘images:add.png’]}” action=”#{dml.CreateInsert}”>
                    <af:setPropertyListener from=”Company1Iterator” to=”#{dml.methodNameorIteratorBinding}”
                                            type=”action”/>
                  </af:button>
                  <af:button id=”b2” action=”#{dml.Previous}” icon=”#{resource[‘images:back.png’]}”>
                    <af:setPropertyListener from=”CompanyPrevious” to=”#{dml.methodNameorIteratorBinding}”
                                            type=”action”/>
                  </af:button>
                  <af:button id=”b3” icon=”#{resource[‘images:next.png’]}” action=”#{dml.Next}”>
                    <af:setPropertyListener from=”CompanyNext” to=”#{dml.methodNameorIteratorBinding}”
                                            type=”action”/>
                  </af:button>
                  <af:button id=”b4” icon=”#{resource[‘images:remove.png’]}” action=”#{dml.Delete}”>
                    <af:setPropertyListener from=”CompanyDelete” to=”#{dml.methodNameorIteratorBinding}”
                                            type=”action”/>
                  </af:button>
                </af:toolbar>

Finally, you have one Back Bean responsible for handle all DML / Navigation operations in any Iterator or Page Defination Actions for all pages in your ADF Application.

No comments:

Post a Comment