Tuesday, November 11, 2014

OAF - Creating Dyanmic Table Region in ProcessFormRequest

Creating a Dynamic table region and attaching the VO to this dynamic Table region in ProcessFormRequest method of controller. 

Consider the requirement,
  • If user selects “U” then it should create table region and should attach the query "select user_name from fnd_user "
  • If user selects “I” then it should create table region and should attach the query  "select invoice_num from ap_invoices_all "



Enter “I” and click Submit button.

The result will be Invoice Information.

Enter the “U” and click Submit button.

Result will be User information.

Note:
We cannot directly modify web bean properties in ProcessFormRequest method in controller. If you try, you will get below error.
(This developer mode error is thrown instead of being registered due to the lack of the page context object.) The OA passivation framework coding standard has been violated. Web bean properties cannot be modified in the controller processFormData or processFormRequest method. Web bean properties should be modified in the processRequest method only. An attempt to modify a web bean has been made in the following call stack: java.lang.Throwable at oracle.apps.fnd.framework.OACommonUtils.getCallStack(Unknown Source) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.addIndexedChild(Unknown Source) at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.addIndexedChild(Unknown Source) at xxtab.oracle.apps.po.dynamictab.webui.xxtabCO.processFormRequest(xxtabCO.java:106) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest(Unknown Source) at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processFormRequest(Unknown Source) at oracle.apps.fnd.framework.webui.OAPageLayoutHelper.processFormRequest(Unknown Source) at oracle.apps.fnd.framework.webui.beans.layout.OAPageLayoutBean.processFormRequest (Unknown Source) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequestChildren(Unknown Source) at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processFormRequest


Solution:
Please check below things if this is helpful.

Step 1: Write the code for creating the table region dynamically  in ProcessRequest method in controller. Initially set a Flag as ‘No’.

Step 2: On clicking the Submit button , set the flag to ‘Yes’ and get the parameter value from Input Textbox in ProcessFormRequest method in controller

Step 3: Using forwardImmediatelyToCurrentPage  method load the same page once again

Step 4: Based on the flag and parameter value, proceed to the dynamic table region and attach VO query  logic in ProcessRequest method in controller.

Code Snippet - ProcessRequest and ProcessFormRequest method

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);   
    String xflag = "N";   
    String aparam = "";
    String voquery = "";
    if (pageContext.getTransactionValue("xflag") != null && !pageContext.getTransactionValue("xflag").equals(""))
        xflag = pageContext.getTransactionValue("xflag").toString();
   
    System.out.println("Flag="+ xflag);
    if ( xflag == "Y" )
    {
        if (pageContext.getTransactionValue("param") != null && !pageContext.getTransactionValue("param").equals(""))
            aparam = pageContext.getTransactionValue("param").toString();
           
        System.out.println("aparam="+ aparam);    
       
        if (aparam == "U" || aparam.equals("U"))
        {
             voquery = "select user_name from fnd_user ";  
        }
        else if (aparam == "I" || aparam.equals("I"))
        {
             voquery = "select invoice_num from ap_invoices_all ";
        }
        else
        {
            voquery = "select user_name from fnd_user ";
        }
       
        System.out.println("voquery="+ voquery);
       
        AttributeDef[] attrdef = null;     
        OAApplicationModule  oam = pageContext.getApplicationModule(webBean);
        ViewObject vo = oam.findViewObject("xxVO");
     
        if(vo != null)     
        {
            vo.remove();
            vo = oam.createViewObjectFromQueryStmt("xxVO",voquery);
        }
        else
        {
            vo = oam.createViewObjectFromQueryStmt("xxVO",voquery);
        }               
     
                                vo.executeQuery();      
                                attrdef = vo.getAttributeDefs();     
               
        String colprompt = attrdef[0].getName();
        System.out.println("colprompt"+colprompt);      
                                OATableBean tabbean = (OATableBean)createWebBean(pageContext,TABLE_BEAN,null,"table");      
                                tabbean.setID("TableBN");
                                tabbean.setNumberOfRowsDisplayed(10);
                                tabbean.setWidth("50%");
                                tabbean.setUserCustomizable(true);
                                tabbean.setViewUsageName("xxVO");      
     
                                OAMessageStyledTextBean beans = (OAMessageStyledTextBean)createWebBean(pageContext,MESSAGE_STYLED_TEXT_BEAN,null,"beans");      
                                beans.setID("col"+colprompt+"0");
                                beans.setViewUsageName("xxVO");
                                beans.setViewAttributeName(colprompt);
                                beans.setLabel(colprompt);
                                beans.setUserCustomizable(true);
                                beans.setWrapEnabled(true);
                                beans.setDataType("VARCHAR2");
     
                                tabbean.addIndexedChild(beans);
                                webBean.addIndexedChild(tabbean);
    }    
      
  }

  /**
   * 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("item2")!= null) // Go button
    {
        String param = pageContext.getParameter("item1");//To get text box value
        pageContext.putTransactionValue("xflag","Y");
        pageContext.putTransactionValue("param",param);
        pageContext.forwardImmediatelyToCurrentPage(null,true, "Y");
    }
   }



3 comments: