Tuesday, 18 November 2014

How to set where clause programmatically in OAF?



Imagine this is the query in your VO:

select  empno,name from Employee;


So in this query you want to set the where clause programatically run time. So what you do is in your VOImpl.java file where you are writing the initQuery method use the below code:

vo.setWhereClause(null);
vo.setWhereClauseParams(null);
vo.setWhereClause("employee_number = :1 and Person_id = :2");
vo.setWhereClauseParam(1,empno);
vo.setWhereClauseParam(2,personid);
vo.executeQuery();



Below example shows coding handled in CO

  public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
          if(pageContext.getParameter("item3")!=null)
    {
  /* The below code line is used to initialize the application module */
    OAApplicationModule am=(OAApplicationModule)pageContext.getApplicationModule(webBean);
  /* The below code line is used to initialize VO*/
    XxepmVOImpl vo=(XxepmVOImpl)am.findViewObject("XxepmVO1");

    String from_date = pageContext.getParameter("item1");
    String to_date = pageContext.getParameter("item2");

    vo.setWhereClause(null);
    vo.setWhereClauseParams(null);
    vo.setWhereClause("to_date(XxepmEO.START_DATE,'DD-MM-RRRR') between to_date(:1,'DD-MON-RRRR') and to_date(:2,'DD-MON-RRRR')");
    vo.setWhereClauseParam(0,from_date);
    vo.setWhereClauseParam(1,to_date);
    vo.executeQuery(); 

    
 //   String message = String.valueOf(am);
   // String message = String.valueOf(vo);
//throw new OAException(from_date, OAException.INFORMATION);
  /* DataDisplayVO1 is the instance name in AM which is the original name of the VO */
   // vo.executeQuery();
     }
  }




No comments:

Post a Comment