Thursday 20 October 2011

Creation of ViewObject Dynamically...

Requirement:

 I have one seeded page..In that page i have 4 input parameters..and also i have one table...and one apply, cancel and add another button is there. When i provide the values in that page and when i click on "Apply" button, the values has to be inserted into the back-end and as well as the values has to be displayed in the seeded page. This is already there in the existing functionality. Now my requirement is to "When the use provide  values in the same page with same values, now this time i have to through the exception"


Now for this i had done, controller extension..and personalization..so for that i created a dynamic view object and doing some validation..

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
    stopDelieveryManager(pageContext, webBean);
  }
 public void stopDelieveryManager(OAPageContext pageContext, OAWebBean webBean)
{
//OAViewObject vo = (OAViewObject)am.findViewObject("AddNewProjectPartiesVO");
OAApplicationModule am = pageContext.getApplicationModule(webBean);

// Read the values from the page
String  getApply =  pageContext.getParameter("Apply");
String sDate = pageContext.getParameter("StartDate");
String eDate = pageContext.getParameter("EndDate");
String resourceId=pageContext.getParameter("ResourceId");
OADBTransaction oadbtransaction = am.getOADBTransaction();
String projectId = (String)pageContext.getSessionValue("paProjectId");
String sWhereClauseValue = "";

if(getApply!=null)
{
   
String dynVoQuery = "SELECT distinct 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 pp.project_id=ppp.project_id AND ppp.project_role_type = ppr.project_role_type   AND pp.project_role_id =ppr.PROJECT_ROLE_TYPE  AND ppp.project_id = :1   AND ppr.description = 'Delivery Manager'   AND  NVL (ppp.end_date_active, NVL (pp.START_DATE_ACTIVE, SYSDATE)) BETWEEN NVL (:2, SYSDATE) AND NVL (:3, TO_DATE ('01/01/4712', 'DD/MM/YYYY'))";

ViewObject validateViewObject1 = (ViewObject)am.findViewObject("AddProjectPartiesVO");

if (validateViewObject1 == null)
  validateViewObject1 = (ViewObject)am.createViewObjectFromQueryStmt("AddProjectPartiesVO", dynVoQuery);

if (validateViewObject1 != null)
{
    validateViewObject1.setWhereClause(null);
    validateViewObject1.setWhereClauseParams(null);

    ArrayList params = new ArrayList(3);
    params.add(projectId);
    params.add(sDate);
    params.add(eDate);
    validateViewObject1.setWhereClauseParams(params.toArray());
    validateViewObject1.executeQuery();


    /* validateViewObject1.setWhereClauseParam(0, projectId);
    validateViewObject1.setWhereClauseParam(1,sDate);
    validateViewObject1.setWhereClauseParam(2,eDate);
    validateViewObject1.executeQuery(); */

    //validateViewObject1.reset();

//oracle.jbo.Row validaterow = validateViewObject1.first();

    OAViewObject vo = (OAViewObject)am.findViewObject("AddProjectPartiesVO");
        AddProjectPartiesVORowImpl 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 = (AddProjectPartiesVORowImpl)insertIter.getRowAtRangeIndex(i);
          String existingDeliveryMgr = row.getAttribute(0).toString();   
          if(existingDeliveryMgr != resourceId)
          {
              //throw new OAException("Duplicate Delivery Manager Exist");
              MessageToken[] tokens = { new MessageToken(null, null)};
                  OAException exception =  new OAException("PA","DELIEVERY_MANAGER_ERR_MSG",tokens,OAException.ERROR,null);
              pageContext.putDialogMessage(exception);
          }
        }
          insertIter.closeRowSetIterator();

        }//outer if
}      
        validateViewObject1.remove();

}//apply close
}//method close


No comments:

Post a Comment