Apr 8, 2016

Programmatically get and set Iterator Key value from Managed Bean

Sometimes we need to set current row after performing some action like Rollback or Execute.



BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter = (DCIteratorBinding) bindings.get("EmployeesIterator");
oracle.jbo.Key empKey = null;

// get key value of current row

                if (iter.getEstimatedRowCount() > 1) {
                    if (iter.getCurrentRow() != null) {
                        empKey = iter.getCurrentRow().getKey();
                    }
                }

// Perform action you want to do here

// set ket value of current row

            if (empKey != null) {
                iter.setCurrentRowWithKey(empKey.toStringFormat(true));
            }



Programmatically Call and execute Iterator from Managed Bean

Below code is use to get Iterator and Execute Iterator:-

BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter= (DCIteratorBinding) bindings.get("EmployeeIterator");
iter.executeQuery();



Mar 2, 2016

Call Stored Database Function in ADF

Sometimes we need to call stored database function in ADF application.

Note :- Try to call stored database function in ApplicationModuleImpl Class or in ViewObjectImpl.

Use below method to call stored function.


import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Types;
import oracle.jbo.JboException;

/**Method to call Database function
     * @param sqlReturnType (Return type of Function)
     * @param stmt (Function Name with Parameters)
     * @param bindVars (Parameter's Value)
     * @return
*/

    protected Object callStoredFunction(int sqlReturnType, String stmt, Object[] bindVars) {


        CallableStatement st = null;
        try {
      //Creating sql statement
            st = this.getDBTransaction().createCallableStatement("begin ? := " + stmt + ";end;", 0);

      //Register dataType for return value
            st.registerOutParameter(1, sqlReturnType);
     //Pass input parameters value
            if (bindVars != null) {

                for (int z = 0; z < bindVars.length; z++) {

                    st.setObject(z + 2, bindVars[z]);

                }
            }

            st.executeUpdate();
      //Finally get returned value
            return st.getObject(1);
        } catch (SQLException e) {
            throw new JboException(e.getMessage());
        } finally {
            if (st != null) {
                try {
                    st.close();
                } catch (SQLException e) {
                      e.printStackTrace();
                }
            }
        }
    }


Use above callStoredFunction method in a method in Impl class and pass parameter.


public String callFunction(Integer EmployeeId){

    String EmpNm =null;



    Object obj = callStoredFunction(Types.VARCHAR, "fn_getEmpNm(?)", new Object[] {  EmployeeId     });


    if(obj!= null) {
      EmpNm =obj.toString();
    }


    return EmpNm ;
}



Feb 27, 2016

Passing parameter in dynamic region using managed bean

For Demo Purpose I have created 2 application having same Input parameter.

1.)  First Application :-
   

   

I have created a Taskflow with Input Parameter name Parameter1.





I have used page show value the input parameter of










2.) Same as first application I have created second application with same input parameter.


















Now create ADF jar file of both application and call this two application in Master application.


3.) Create Master App

  •  Create a jspx page in Master Application to call above applications.



  • Now drag and drop task flow of Demo app 1



    Select Dynamic Region



    Now Select a Managed bean or create new.


  • Now drag and drop taskflow of another application as link and then first one also.

  • Now next step is to set parameter of taskflow using Hash Map.

    For same we have to declare a Map type variable in bean.

    private Map<String, Object> parameterMap = new HashMap<String, Object>();

    and create its Accessors.
  • Now set its value using below code.





  • Now pass hash map value to parameter.

    import java.io.Serializable;
    import java.util.HashMap;
    import java.util.Map;
    import oracle.adf.controller.TaskFlowId;
    
    public class DRBean implements Serializable {
    
        private String taskFlowId = "/WEB-INF/task-flow-definition1.xml#task-flow-definition1";
    
        private Map<String, Object> parameterMap = new HashMap<String, Object>();
    
        public void setParameterMap(Map<String, Object> parameterMap) {
           this.parameterMap = parameterMap;
        }
    
        String srt = "Default First App";
    
        public Map<String, Object> getParameterMap() {
            return parameterMap;
        }
    
        public DRBean() {
            setParameterVal();
        }  
        public TaskFlowId getDynamicTaskFlowId() {      
            return TaskFlowId.parse(taskFlowId);
        }
        public void setDynamicTaskFlowId(String taskFlowId) {
            this.taskFlowId = taskFlowId;
        }
        public String taskflowdefinition2() {
            srt = "Call Application 2";
            setParameterVal();
            setDynamicTaskFlowId("/WEB-INF/task-flow-definition2.xml#task-flow-definition2");
         
            return null;
        }
    
        public String taskflowdefinition1() {
            srt = "Call Application 1";
            setParameterVal();
            setDynamicTaskFlowId("/WEB-INF/task-flow-definition1.xml#task-flow-definition1");
         
            return null;
        }
    
        private void setParameterVal() {
            parameterMap.put("Parameter1", srt);
    
        }
    }
    

    Goto Page Binding and edit taskflow binding .





    select hash map from expression builder.




    Now run application.

    When we run application




    After Clicking on Call Application 1 Link



    And after clicking on Call Application 2 Link


    We have passed value of input parameter of Task flow using managed bean.