Monday 5 March 2012

Adding New Row to the Advanced Table in Programatical way

                               Adding New Row to the Advanced Table in Programatical way

Step 1: Create sample page

Step 2: Create one Advanced Table in that page

Step 3: Setup the required properties for the page

Step 4: Create on footer for the table, in that create one add table row button

Step 5:
Set the below properties to the Add Table Row button


                  Insert Rows Automatically : False

Step 6: Now in the process Request method add the below code
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
    sampleAMImpl am = (sampleAMImpl)pageContext.getApplicationModule(webBean);
    am.invokeMethod("createInsert1");
    OAAdvancedTableBean tableBean = (OAAdvancedTableBean)webBean.findIndexedChildRecursive("AdvancedTableBean1");
    System.out.println("Advanced Table Bean id--->"+tableBean);
    OATableFooterBean footerBean = (OATableFooterBean)tableBean.getFooter();
    System.out.println("TableFooter bean-->"+footerBean);
    if(footerBean!=null)
    {
      OAAddTableRowBean addTableRowBean =  (OAAddTableRowBean)footerBean.findIndexedChild("addTableRow1");
      System.out.println("Add Table Row Bean id----->"+addTableRowBean);
      // Add 5 rows everytime add row button is clicked
      addTableRowBean.setText("Add 1 Rows");
      addTableRowBean.setRows(1);
      // Handle add row insertion yourself
      addTableRowBean.setAttributeValue(AUTO_INSERTION, Boolean.FALSE);
    }
  } 


Step 7:  In AMImpl Class write the below Code
     public void createInsert1()
  {
    OAViewObject vo =getInsertVO1();
    if (!vo.isPreparedForExecution())  
    {      
      vo.executeQuery();   
    }
   
  }


Step 8: Now in the process Form Request method add the below code
   public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processFormRequest(pageContext, webBean);
     OAAdvancedTableBean tableBean = (OAAdvancedTableBean)webBean.findIndexedChildRecursive("AdvancedTableBean1");
     System.out.println("Advanced Table Bean id--->"+tableBean);
     OATableFooterBean footerBean = (OATableFooterBean)tableBean.getFooter();
     System.out.println("TableFooter bean-->"+footerBean);
     if(footerBean!=null)
     {
       OAAddTableRowBean addTableRowBean =  (OAAddTableRowBean)footerBean.findIndexedChild("addTableRow1");
       System.out.println("Add Table Row Bean id----->"+addTableRowBean);
       if ((tableBean.getName(pageContext).equals(pageContext.getParameter(SOURCE_PARAM))) && (ADD_ROWS_EVENT.equals(pageContext.getParameter(EVENT_PARAM))))
       {
       System.out.println("Add Another row is pressed");
       sampleAMImpl am = (sampleAMImpl)pageContext.getApplicationModule(webBean);
       am.invokeMethod("createAnotherRow1");
       System.out.println("Action over");
       }
     }


Step 9: In Am Impl Class write the below Code

   public void createAnotherRow1()
  {
    InsertVOImpl studVo = getInsertVO1();
    // StudentDetailsVOImpl studVo = getStudentVO1();
    System.out.println(" vo class statement");
    InsertVORowImpl studrow = (InsertVORowImpl)studVo.createRow();
    System.out.println(" vo row impl statement");
    studVo.last();
    System.out.println("vo.last method");
    studVo.next();
    System.out.println("vo.next method");
    studVo.insertRow(studrow); //'ABC' is HardCod value inserted based on the requirement in this example
    System.out.println("insert row method");
    studVo.setCurrentRow(studrow);
    System.out.println("current row method");
    studrow.setNewRowState(Row.STATUS_INITIALIZED);
    System.out.println("Initialized method");
  }


Step 10: Now Run the page and check the functionality of Add Another Row.


5 comments:

  1. This is not working yaar am getting error at this place OATableFooterBean footerBean = (OATableFooterBean)tableBean.getFooter(); am getting java.lang.nullpointer excpetion

    ReplyDelete
    Replies
    1. Please check the output for the below statement.

      or

      What is printing at this statement in your log window.

      System.out.println("TableFooter bean-->"+footerBean);

      and make sure that your table footer bean id is not empty.

      Delete
  2. Advanced Table Bean id--->null
    Here only am getting null but my VO has data and i have given like this
    OAAdvancedTableBean tableBean = (OAAdvancedTableBean)webBean.findIndexedChildRecursive("IpcQuoteInstancesVO1"); this is the VO am using it has data and i want to insert the items in this advanced table yaar.
    can you provide me your cell number or mail id plz.
    Thank you
    Kiran kumar paspulate
    +919676774977

    ReplyDelete
  3. Reach me at santhosh.kumar49@gmail.com and +91-9000594282

    ReplyDelete
  4. Dear
    Can you guide if i want to table to automatically insert 1 row after page render. not by manual click add button

    thanks!!

    ReplyDelete