Thursday 31 May 2012

how to use javascript on submitbutton in OAF page and to stop submit of the form before fill it completely


 public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
   // get the handle of submitButton  and attach the javascirpt functin to it using setOnclick method of OASubmitButtonBean as shown below;
OASubmitButtonBean  sbButton = (OASubmitButtonBean)webBean.findIndexedChildRecursive("SubEmpReq");
sbButton.setOnClick("javascript:var Val=document.getElementById('EmpPositionName').value; if(Val==''){  alert('Fill PostionName'); document.getElementById('EmpPositionName').focus();return (false);}return (true);");
   

  }

Friday 18 May 2012

getting the and setting Individual fields on OA Page by Creating VO object and extracting Data form DB in Controller class

import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
//import oracle.apps.fnd.framework.webui.beans.message.OAMessageChoiceBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;

import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.jbo.ViewObject;
import oracle.jbo.Row;

//import oracle.jbo.AttributeDef;
/**
 * Controller for ...
 */
public class EmpRequisitionController extends OAControllerImpl
{
  public static final String RCS_ID="$Header$";
  public static final boolean RCS_ID_RECORDED =
        VersionInfo.recordClassVersion(RCS_ID, "%packagename%");

  /**
   * Layout and page setup logic for a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
        
   
  }

  /**
   * Procedure to handle form submissions for form elements in
   * a region.
   * @param pageContext the current OA page context
   * @param webBean the web bean corresponding to the region
   */
  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);

     if(pageContext.getParameter("ShowExistingEmp")!=null){
     System.out.println("Show Existing Employee Button Put Logic");

     OAMessageTextInputBean  oatib = (OAMessageTextInputBean)webBean.findIndexedChildRecursive("EmpNo");
     String empno=oatib.getText(pageContext);

     //getting the  handle of displaytextFields(i.e OAMessageStyledTextBean) from OAPage
     OAMessageStyledTextBean  oamstName = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("EmpName");
     OAMessageStyledTextBean  oamstDesignation = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("EmpDesignation");
     OAMessageStyledTextBean  oamstDepartment = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("EmpDepartment");
     OAMessageStyledTextBean  oamstDivision = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("EmpDivision");
     OAMessageStyledTextBean  oamstCity = (OAMessageStyledTextBean)webBean.findIndexedChildRecursive("EmpCity");
    

 //getting the handle of ApplicationModule AM
    OAApplicationModule am= pageContext.getApplicationModule(webBean);

// sql select query  for the View Object to be executed
    String sqlStr = "SELECT * FROM  emprequisition ";

//create ViewObject Dynamically give it the name "A"

    ViewObject vo = am.createViewObjectFromQueryStmt("a",sqlStr);
// set where clause(EMPID the name of Column in DB and empno.value comming from OAPage) of sql for View Object by Passing Dynamically the value of EmpNo textfield on OAPage   
    vo.setWhereClause("EMPID="+empno+" ");
    System.out.println(empno);
   
//Create the Row object by calling the vo.next() function give us the Row Object              
      Row row = vo.next();
       
  // Extracting the Column form the VO using row object by specifing respectively ColumnNames in row.getAttribute function give the vlaue of the field.
           String name=(String )row.getAttribute("EMPNAME");
// passing the name retrived from db  and it set for display on OA page using setText method of OAMessageSyteldTextBean on OA Page along with pagecontext passed.
           oamstName.setText(pageContext,name);

           String designation=(String )row.getAttribute("EMPDESIGNATION");
           oamstDesignation.setText(pageContext,designation);
          
           String department=(String )row.getAttribute("EMPDEPARTMENT");
           oamstDepartment.setText(pageContext,department);

           String division=(String )row.getAttribute("EMPDIVISION");
           oamstDivision.setText(pageContext,division);

           String location=(String )row.getAttribute("EMPLOCATION");
           oamstCity.setText(pageContext,location);
         }
     if(pageContext.getParameter("AmendRequisition")!=null){
    System.out.println("Amend Record Button Put Logic");
    }

}

}

Thursday 17 May 2012

delete,insert, and update at one place in AM (do not use update and delete query of sql note it)


public void deletePersonMethod( String pPersonId ){
  try{  System.out.println("inside deletePersonMethod() i have this id to delete="+pPersonId) ;
  EmprequisitionViewImpl pervo = getEmprequisitionView1();
  String existingWhereClause = pervo.getWhereClause() ;
  pervo.setWhereClauseParams(null);
   pervo.setWhereClause("Empid= :1");
   pervo.setWhereClauseParam(0, new Number(pPersonId));
  pervo.executeQuery();
   System.out.println("row loaded");
   Row row[] = pervo.getAllRowsInRange();
   EmprequisitionViewRowImpl row0 = (EmprequisitionViewRowImpl)row[0];
   row0.remove();
    System.out.println("inside deleted");
  } catch(Exception exception1)   { throw OAException.wrapperException(exception1);   }
 }//end delete function
public void OurInsertMethod( ){
System.out.println("I am insert method in OurInsertMethod"+empid+empname+empdesign+empdepart+empdiv+ emploc );
 //get a handle to the View Object that we wish to initialize
    OAViewObject vo = (OAViewObject)getEmprequisitionView1();
    if(!vo.isPreparedForExecution()){
     vo.executeQuery();
     System.out.println("I have executed the query Query");
    }
  //Create a blank Row
      Row row = vo.createRow();
     System.out.println("I have  created a blank row for the data");
    //Attach that blank row to the VO. Data will be fed into this row, when the user types into the fields
        vo.insertRow(row);
      System.out.println("Attached the blank row to the view");
    //Set the status of the blank row to initialized. This tells OA Framework that record is blank and must not be included in DML
    //Operations until    changes are made to its underlying VO [via screen fields]
    row.setNewRowState(Row.STATUS_INITIALIZED);
    }
public void updatePersonMethod( String pPersonId)  {
  try{  System.out.println(" I have"+ pPersonId);
        EmprequisitionViewImpl pervo = getEmprequisitionView1();
        String existingWhereClause = pervo.getWhereClause() ;
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause("Empid= :1");
        pervo.setWhereClauseParam(0, new Number(pPersonId));
        pervo.executeQuery();
        pervo.setWhereClauseParams(null);
        pervo.setWhereClause(existingWhereClause);
   }
   catch(Exception exception1) { throw OAException.wrapperException(exception1);   }
  }

creating MessageChoiceBean Programatically and attach VO to it.


//add the code to the ProcessRequest() function in controller class.
String sMode = "test";
//Getting  application module object;
OAApplicationModule am = pageContext.getApplicationModule(webBean);
//create or create exiting  View  object;
OAViewObject oaviewobject = (OAViewObject)am.createViewObject("xxScoResourceVO1","xx.oracle.apps.pa.poplist.server.testVO");
//Setting where clause Dynamically of Poplist VO
oaviewobject.setWhereClause("DESCRIPTION IS NULL OR DESCRIPTION = '" + sMode + "'");
//execute the query of vo.
oaviewobject.executeQuery();
//create  object of OAMessageChoiceBean  class.
OAMessageChoiceBean oamessagechoicebean = (OAMessageChoiceBean)createWebBean(pageContext, "MESSAGE_POPLIST");
//setting the properties of OAMessageChoiceBean Class
oamessagechoicebean.setPrompt("Back");
//setting or attach the view object  with the MessageChoiceBean.
oamessagechoicebean.setListViewObject(pageContext, oaviewobject);
//setting or attach the  attribute/columns of  view object  with the MessageChoiceBean.
oamessagechoicebean.setListDisplayAttribute("Meaning");
//setting or attach the  attribute/columns of  view object  with the MessageChoiceBean.
oamessagechoicebean.setListValueAttribute("LookupCode");
 //setting other  necessary value for MessageChoiceBean.
oamessagechoicebean.setName("xxAddAsgmtApplyAction");
oamessagechoicebean.setAllowBlankValue(false);
oamessagechoicebean.setDefaultValue("RETURN_BACK"); //Setting Default Value
webBean.addIndexedChild(oamessagechoicebean);

Thursday 3 May 2012

Delete Method for OAF in AM Class

public Boolean deleteEmployee(String EmployeeId)
{
System.out.println("I am in deleteFunction");
// First, we need to find the selected EmployeeId in our VO.
// When we find it, we call remove( ) on the row which in turn
// calls remove on the associated PurchaseOrderHeaderEOImpl object.
//int poToDelete = .parseInt(EmployeeId);
OAViewObject vo = (OAViewObject)getEmprequisitionView1();
Row row[]=vo.getAllRowsInRange();
for(int i=0; i<row.length;i++){
EmprequisitionViewObjectRowImpl row1=(EmprequisitionViewObjectRowImpl) row[i];
System.out.println(row1.getEmpid());
  if(row1.getEmpid().toString().equals(EmployeeId)){
     row1.remove();
     getDBTransaction().commit();
     }
}

return new Boolean("true");
} // end