Sunday 24 November 2013

                           How  To  Debugg Errors in OAF



Debugging Errors in Local Machine




1. Using sop Statments In Controller:

        system.out.println(" Enters into The statement");

2.Using Internal Debugger in the Statement:


Put Break points Which You Want to run




After run The page It shows Arrow mark on the Code . so Press F9. it follow the flow and if any Error is there it skips the flow. we Can see this is logg window.


Debugg  Errors  in Server:

Here we can Debug using Following statement  in Controller:

 pageContext.writeDiagnostics(this, "I am at disble item3", 
                                     OAFwkConstants.STATEMENT);


IN AM:

OADBTransaction.writeDiagnostics(this, "I am at disble item3", 
                                     OAFwkConstants.STATEMENT);


Using Diagnostics:




  











Passing parameters from one OAF page to another OAF Page




Ways to pass parameters in Request:

·                     Adding in URL: We can specify parameters as literal values or token substituted values (mapped to VO Attributes). Following are the examples:
o                  OA.jsp?page=/xxabc/oracle/apps/xxabc/custommodule/webui/CustomPG&order={@OrderNum}
o                  OA.jsp?OAFunc=XXABC_ADM_SUPP_ENGR&asset=123
·                     OAPageContext.putParameter()
o                  Values are not technically added to request, but are stored in a special page cache.
o                  Equivalent to HttpServletRequest.setAttribute()
·                     Hidden fields (form values)
·                     Passing parameters in Hashmap using setForwardUrl().
1.HashMap xxhashMap = new HashMap(1);
xxhashMap .put("ParamName1", "Value1");

oapagecontext.setForwardURL("MY_FUNCTION", (byte)0, null, xxhashMap , true, "N", (byte)0);

OR
oapagecontext.setForwardURL("OA.jsp?page=/xxelng/oracle/apps/per/hiring/webui/XXConfermationPG", 
                                      null,
 
                                      OAWebBeanConstants.KEEP_MENU_CONTEXT,
 
                                      null, xxhashMap , true,
 
                                      OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
 
                                      OAWebBeanConstants.IGNORE_MESSAGES);

You can then retrieve this parameter in processRequest() via:
oapagecontext.getParameter("ParamName1");


Passing parameters in Hashmap is the better approach for following reasons:
1.             URL has size restrictions.
2.             URL is visible to users.
3.             putParamater() and hidden fields are not stored in Request as parameters, thus if we navigate with Breadcrumbs or for other reasons in case the webBean hierarchy needs to be reconstructed, these will not be available.

Transaction:

Transaction has wider scope than Request thus its not preferred approach.
·                     OAPageContext.putTransactionValue()
·                     OAPageContext.getTransactionValue()
·                     ((OADBTransactionImpl)getTransaction()).putValue()
·                     ((OADBTransactionImpl)getTransaction()).getValue()

Session:

Again, a wider scope than Transaction and not recommended.

·                     pageContext.putSessionValue();
·                     pageContext.getSessionValue();



Multi Delete in OAF


1. Create Item Under rowlayout Region Style SubmitButton Id&Prompt: MultiDelete
2. Create Transist Attribute in XXSearchVO Name:XXMDelete, Type:String
3. Rt Click on Table Region_MultipleSelection_InProperties
     View Instance: XXSearchVO
     View Attribute: XXMDelete(TransistAttribute)
4. Write Code SearchCO in ProcessFoamRequest
    if(pageContext.getParameter("MultiDelete")!=null)
{
OAViewObject vo=(OAViewObject)am.getXXSearchVO1();
for (XXSearchVORowImpl row=(XXSearchVORowImpl)vo.first();
row!=null;row=(XXSearchVORowImpl)vo.next())
{
if(row.getAttribute("XXMDelete")!=null && row.getAttribute("XXMDelete").equals("Y"))
{
String hid=row.getAttribute("HeaderId").toString();
String query="delete from XXCUSTOMER_REBATELINE where HEADER_ID="+hid;
try
{
PreparedStatement
ps=am.getOADBTransaction().getJdbcConnection().prepareStatement(query);
ps.executeUpdate();
}
catch (Exception e)
{
e.printStackTrace();
}
row.remove();
am.getOADBTransaction().commit();
} } }
Capturing Values from Lov()
if (pageContext.isLovEvent())
    {
      pageContext.writeDiagnostics(this, "I am at disble item2",
                                   OAFwkConstants.STATEMENT);
      String lovid = pageContext.getLovInputSourceId();

      if ("Category".equals(lovid))
      {
        pageContext.writeDiagnostics(this, "I am at disble item3",
                                     OAFwkConstants.STATEMENT);
        String category = pageContext.getParameter("Category").toString();
        pageContext.writeDiagnostics(this, "I am at disble item4" + category,
                                     OAFwkConstants.STATEMENT);

        
Creating the button programmatically

  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    //first excute standard functionality by call super as below
    super.processRequest(pageContext, webBean);
    //now create new button programatically
    OASubmitButtonBean oasb= (OASubmitButtonBean)pageContext.getWebBeanFactory().createWebBean(pageContext,"BUTTON_SUBMIT");
    oasb.setID("xxSubmitSendEmailButton");
    oasb.setUINodeName("xxSubmitSendEmailButton");
    oasb.setEvent("xxSubmitSendEmailButton");
    oasb.setText("xxSubmitSendEmailButton");
    webBean.addIndexedChild(oasb);
  }

Dynamically creating of Advance Table  Bean:

 private void setReportSumText(OAPageContext pageContext, OAWebBean webBean) 
  {
    OAAdvancedTableBean advancedTableBean = (OAAdvancedTableBean)webBean.findIndexedChildRecursive("BuyerTableRN");
    advancedTableBean.prepareForRendering(pageContext);
    if (advancedTableBean != null)
    {
      OATableFooterBean tableFooterBean = (OATableFooterBean)advancedTableBean.getFooter();
      if(tableFooterBean != null)
      {
        OATotalRowBean totalRowBean = (OATotalRowBean)tableFooterBean.getTotal();
        if(totalRowBean != null)
        {
          totalRowBean.setText("Report-Sum");
        }
      }
   }
  }
Loop Throught the Fetched Records in VO
Example 1:

This particular example was written for Oracle Sourcing.
       OAApplicationModule rootAM = pageContext.getRootApplicationModule();           
       OAViewObject ReqVO   =      (OAViewObject)rootAM.findViewObject("BidHeaderSectionsVO");
           
            if (null!=ReqVO) {
                Row ReqRow = ReqVO.first();           
                if (null != ReqRow) {
                           
                int idx = ReqVO.getRowCount();
   
                for (int xx = 0; xx < idx; xx++) {
                    if (null != ReqRow) {
                       // Do some work....
                       ReqRow = ReqVO.next();
                    }
                    else {}
                }
              }
            }

Example 2:
OAViewObject vo = (OAViewObject)getPPVCMHeadersVO2();
   PPVCMHeadersVORowImpl row = null;
   int fetchedRowCount = vo.getRowCount();
   RowSetIterator insertIter = vo.createRowSetIterator("insertIter");
   if (fetchedRowCount > 0)
    {
     insertIter.setRangeStart(0);
     insertIter.setRangeSize(fetchedRowCount);
     for (int i = 0; i < fetchedRowCount; i++)
      {  
        row = (PPVCMHeadersVORowImpl)insertIter.getRowAtRangeIndex(i);
        row.setAttribute("Sno",new Integer(i+1));
      }
    }  



How to add where condition to the sql stament....?


public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    String resourceId=pageContext.getParameter("ResourceId");
    OAApplicationModule am = pageContext.getRootApplicationModule();
     String projectId = (String)pageContext.getSessionValue("paProjectId");
    String sWhereClauseValue = "";

    String dynVoQuery = "SELECT ppp.person_id, ppp.start_date_active, ppp.end_date_active  FROM pa_project_players ppp, pa_project_role_types ppr,pa_project_parties pp WHERE ppp.project_id = :1 and pp.project_id=ppp.project_id   AND ppp.project_role_type = ppr.project_role_type AND ppr.description = 'Delivery Manager' AND pp.project_role_id =ppr.PROJECT_ROLE_TYPE AND NVL (ppp.end_date_active, NVL (pp.START_DATE_ACTIVE, SYSDATE)) BETWEEN NVL (pp.START_DATE_ACTIVE, SYSDATE) AND NVL (pp.END_DATE_ACTIVE, TO_DATE ('01/01/4712', 'DD/MM/YYYY'))";
    ViewObject dynViewObject = am.findViewObject("ExistingDeliveryMgrVO");
    if(dynViewObject == null)
    {
      dynViewObject = am.createViewObjectFromQueryStmt("ExistingDeliveryMgrVO", dynVoQuery);
//      ExistingDeliveryMgrVORowImpl row=null;
      dynViewObject.setWhereClauseParams(null);
      dynViewObject.setWhereClauseParam(0,projectId);
      dynViewObject.executeQuery();
      if(dynViewObject.getRowCountInRange() >0)
      {
        oracle.jbo.Row row1 = dynViewObject.first();
        if(row1 != null)
        {
          String existingDeliveryMgr = row1.getAttribute(0).toString();
          if(existingDeliveryMgr != resourceId)
          {
            throw new OAException("Duplicate Delivery Manager");
          }
        }
      }

Call Procedure in OAF (2 input parameters)

 

Call a custom procedure. Two input parameters of type Varchar:
 OAApplicationModule oam =  pageContext.getApplicationModule(webBean);

 String sql =  "BEGIN xx_custom_pkg.custom_prc (:1,:2); END;";
                    try {
                        OracleCallableStatement cs =
                            (OracleCallableStatement)oam.getOADBTransaction().createCallableStatement(sql,
                                                                                                      2);
                        cs.setString(1, xxAttribute1Value);
                        cs.setString(2, xxAttribute2Value);
                        cs.execute();
                        cs.close();
                      }
                 catch (Exception ex) {
                        pageContext.writeDiagnostics(this,
                                                     "Error:" + ex.toString(),
                                                     OAFwkConstants.PROCEDURE);
                    }




Call Procedure in OAF (1 input, 1 output parameter)

String sql = "BEGIN xx_custom_pkg.custom_prc (:1,:2); END;";
            try {
                OracleCallableStatement cs =
                    (OracleCallableStatement)oam.getOADBTransaction().createCallableStatement(sql,
                                                                                              2);
                ((OracleCallableStatement)cs.registerOutParameter(2,
                                                                  Types.VARCHAR,
                                                                  0, 2000));
                cs.setString(1, xxAttribute1Value);
                cs.execute();
                String outParamValue = cs.getString(1);
                pageContext.writeDiagnostics(this,
                                             "Result is:" + outParamValue,
                                             OAFwkConstants.PROCEDURE);
                cs.close();
            } catch (Exception ex) {
                pageContext.writeDiagnostics(this, "Error:" + ex.toString(),
                                             OAFwkConstants.PROCEDURE);
            }





Call Function in OAF

The segment below calls a custom function with 1 input parameter of type Varchar and returns a Varchar :

   OAApplicationModule oam = pageContext.getApplicationModule(webBean);

   String sql =   "BEGIN :1 := xx_custom_pkg.call_custom_function (:2); END;";

  OracleCallableStatement cs =
                            (OracleCallableStatement)oam.getOADBTransaction().createCallableStatement(sql,2);

                        try {
                             //Register your function output...
                            cs.registerOutParameter(1, Types.VARCHAR, 0, 2000);
                            //Your input parameter below...
                            cs.setString(2, LinesRow.getAttribute("ReportLineId").toString());
                            cs.execute();
                            String p_res = cs.getString(1);
                            cs.close();       
                            }
                        catch (Exception ex) {
                                        pageContext.writeDiagnostics(this,
                                                                     "Error:" + ex.toString(),
                                                                     OAFwkConstants.PROCEDURE);
                           }                    



Programmatically Adding the Fire Partical Action to a Bean

 



import oracle.cabo.ui.action.FireAction;

import oracle.cabo.ui.action.FirePartialAction;

OAMessageChoiceBean mb=(OAMessageChoiceBean)webBean.findChildRecursive("BeanId");

FireAction firePartialAction = new FirePartialAction("DelAction");

mb.setAttributeValue(PRIMARY_CLIENT_ACTION_ATTR,firePartialAction);

 


Gruoping Radio Buttons in OAF

Hi all like in forms there is no declarative way to group Radio Buttons in OAF we have to group them dynamically some sample working  code 

import oracle.apps.fnd.framework.webui.beans.message.OAMessageRadioButtonBean;
 just import this package

=          (OAMessageRadioButtonBean)webBean.findIndexedChildRecursive("RadioBtn1");
 OAMessageRadioButtonBean rb2 =            (OAMessageRadioButtonBean)webBean.findIndexedChildRecursive("RadioBtn2");
         rb1.setName("ChoiceRadioGroup");
         rb2.setName("ChoiceRadioGroup");
         rb1.setValue("New");
         rb2.setValue("Update");
    OAMessageRadioButtonBean rb1         rb1.setSelected(true);

where RadioBtn1,RadioBtn2 are the id of the Radio Buttons

to get selected value
     String radioGroupValue = pageContext.getParameter("ChoiceRadioGroup");
In above Example String radioGroupValue will be New,Update on selecting the First and Second radio buttons respectively




Obtaining Row Reference from a radio Button

reate a row button on table region  by select Selection When we click the radio Button a action will be fired. That we can obtain in CO and process in AM. This is very useful in Master Detail Relationship
Here we get a value by the radio Box check and we will pass to AM and we pass the obtained value to a VO as a param.
 Code in CO to obtain the row reference
String rowReference = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);    //Obtaining the Row Reference of the current Row
OAApplicationModule am1 =(OAApplicationModule) pageContext.getApplicationModule(webBean);
Serializable[] s={rowReference};//    Sending the parameter thro a Serializable parameter
am1.invokeMethod(“obtainRow”, s);//invoking the Method in AM
Code in AM to process  the row reference
public void obtainRow(String rowRef)

{
OAViewObject vo = (OAViewObject)getxxCustVO();
OARow row = (OARow)findRowByRef(rowRef); //Getting the rowRefence and getting as a row
System.out.println(“VO Current Row “+ vo.getCurrentRowIndex()+” “+row.getAttribute(“SelectFlag”));
if (row!=null)
{
System.out.println(row.getAttribute(“CustomerId”));
Number CustNum = (Number)row.getAttribute(“CustomerId”); //Obtaining Value from a Attribute and storing in a variable
// int CustNum = Integer.parseInt(custNum);
System.out.println(“VO getAttribute “+CustNum);
OAViewObject addrvo = (OAViewObject)getxxCustAddrVO();
addrvo.setWhereClause(“Customer_id = :1″);
addrvo.setWhereClauseParams(null);;
addrvo.setWhereClauseParam(0,CustNum);
addrvo.executeQuery();
}

Methods to Iterate Row in OAF

 

 

 Method — 1 */
public String account2Validation(OAViewObject vo, OAViewRowImpl row, String k)
{
int counter=0;
if((vo!=null))
{

//for(xxcactBankValiVORowImpl row=(xxcactBankValiVORowImpl)vo.first(); row!=null; row=(xxcactBankValiVORowImpl)vo.next())//Where the class is rowImpl which can be used within the controller code
for(row = (OAViewRowImpl) vo.first(); row!=null; row = (OAViewRowImpl) vo.next()) //Iterating using For loop
{
String primaryKey=(row.getAttribute(“AccNo”)).toString();
// String primaryKey=(row.getAccNo()).toString(); //This apples when the variable is declared with directly with the class like –> (xxcactBankValiVORowImpl row)
System.out.println(“Value of the Obtained Value”+(row.getAttribute(“AccNo”)).toString());
if (primaryKey.compareTo(k) == 0)
{
System.out.println(“Values Match and “+primaryKey);
counter++;
break;
}
else
{
System.out.println();
}

}
try{
if(counter==0)
{
OAException message = new OAException(“This is a invalid number.”,OAException.ERROR);
// return “invalid”;
pageContext.putDialogMessage(message);
}
}
catch(OAException e)
{
System.out.println(e);
}

}
return counter+”"; //This is Actually a fastest method to convert a int to String
}




/* Method –> 2 */


public String account1Validation(OAViewObject vo, OAViewRowImpl row, String k, String col)
{
System.out.println(“Control came to Account Validation”);
int counter=0; // Introducing a counter variable for us to count
String iteratedval=null; //Iteration varable
System.out.println(k);
if((vo!=null))
{
vo.first();
while(vo.hasNext()) // Loop through VO rows
{
if(vo.getCurrentRow().getAttribute(col)!=null)
iteratedval=(vo.getCurrentRow().getAttribute(col).toString());
System.out.println(“———————————————->”+vo.getCurrentRow().getAttribute(col)+”Something Comes in “+iteratedval);
if (iteratedval.compareTo(k) == 0)
{
System.out.println(“Values Match and “+iteratedval);
counter++;
break;
}
vo.next();
}
try
{
if(counter==0)
{
OAException message = new OAException(“This is a invalid number.”,OAException.ERROR);
pageContext.putDialogMessage(message);
}
}
catch(OAException e)
{
System.out.println(e);
}
}
return counter+”"; //This is Actually a fastest method to convert a int to String
}



/* Method –> 3 Using RowSetIterator*/


public String accountValidation(OAViewObject vo, OAViewRowImpl row, String k1, String col)
{
int counter = 0;
int k=Integer.parseInt(k); //Parsing Value To int
xxcactBankValiVORowImpl row = null; //Assigning a variable for Row to get Attributes
vo.getRowCount(); //Getting the Values of Row Count This is important because when FetchedRowCount() method is called
int fetchedRowCount = vo.getFetchedRowCount(); //Obtaining the Fetched Row Count
System.out.println(“Value Of Fetched Row Count “+fetchedRowCount);
RowSetIterator rowsetiterator = vo.createRowSetIterator(“MyTestIter”); //creating a Iterator
System.out.println(“Row Iterator has been Created”+rowsetiterator);
if (fetchedRowCount > 0)
{
rowsetiterator.setRangeStart(0); //Assiging the Range
rowsetiterator.setRangeSize(fetchedRowCount);
for (int i = 0; i < fetchedRowCount; i++)
{
row = (xxcactBankValiVORowImpl)rowsetiterator.getRowAtRangeIndex(i); //Iterating and passing values for each row to get printed
System.out.println(“xxcactBankValiVO Current Row ————————————————————->”+vo.getCurrentRowIndex()+”Acc No Before”+row.getAccNo());

System.out.println(“Obtaining the from Row Set Iterator”+row);
Number primaryKey = row.getAccNo();// Getting the Value of Each Attributes
int b=row.getAttributeCount(); //Obtainging the Attribute Count
System.out.println(“Value of Account Number”+primaryKey+” Value of Balance”+a+”Value of Attribute Count “+b);
if (primaryKey.compareTo(k) == 0)
{
System.out.println(“Values Match and “+primaryKey);
counter++;
break;
}
}


}

try
{
if(counter==0)
{
OAException message = new OAException(“This is a invalid number.”,OAException.ERROR);
pageContext.putDialogMessage(message);
}
}
catch(OAException e)
{
System.out.println(e);
}
// Always close the iterator when you’re done.
rowsetiterator.closeRowSetIterator();
return counter+”";
}