Monday, 11 July 2011

How To create a submit Button Programmatically

Following sequence of events will take place for this type of extension:

The extended custom controller class will replace the standard controller class.
Just prior to the page being rendered, processRequest of extended controller will be called.
In processRequest we will create a Submit Button Bean using getWebBeanFactory(),as in sample below.
Next, we will attach an event named "xxSubmitSendEmailButton" to this newly created button.
In the processFormRequest of extended controller, trap the event named "xxSubmitSendEmailButton"
        Note- Event is trapped by checking the value of pageContext.getParameter(EVENT_PARAM)
Take appropriate action when this event is trapped

//add these import, if not already exist
import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
//First create the Submit Button
  public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    //first excute standard functionality by call super as below
    super.processRequest(pageContext, webBean);
    //now create new button programatically
    OASubmitButtonBean oasb= (OASubmitButtonBean)pageContext.getWebBeanFactory().createWebBean(pageContext,"BUTTON_SUBMIT");
    oasb.setID("xxSubmitSendEmailButton");
    oasb.setUINodeName("xxSubmitSendEmailButton");
    oasb.setEvent("xxSubmitSendEmailButton");
    oasb.setText("xxSubmitSendEmailButton");
    webBean.addIndexedChild(oasb);
  }
 
 
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
  {
  super.processFormRequest(pageContext, webBean);
  String strEvent= pageContext.getParameter(EVENT_PARAM) ;
  if ( strEvent.equals("xxSubmitSendEmailButton"))
  {
    //IMPORTANT Get this by calling the Function that loops for records.
    //The string will contain the concatenation Email for which STANDARD CHECKBOX WAS CHECKED
    String strEmailStringLearner = "itraj21@gmail.com" ;
    pageContext.setForwardURL("xxMailOTA.jsp?paramEmailLearner="+ strEmailStringLearner,
                             null, // not necessary with KEEP_MENU_CONTEXT
                             OAWebBeanConstants.KEEP_MENU_CONTEXT, // no change to menu context
                             null, // No need to specify since we're keeping menu context
                             null, // request parameters
                             true, // retain the root application module
                             OAWebBeanConstants.ADD_BREAD_CRUMB_YES, // display breadcrumbs
                             OAException.ERROR); // do not forward w/ errors
  }}
 


 On your PC, in <JDEV_USER_HOME>/myhtml/OA_HTML
create a jsp file xxMailOTA.jsp, with below contents
<head>
    <script type="text/javascript">
  function xxRzbCallEmail(paramEmailLearner){
  document.location.href='MailTo:'+paramEmailLearner;history.go(-1);
  }
    </script>
</head>
<%
String paramEmailLearner = request.getParameter("paramEmailLearner");
System.out.println ( "paramEmailLearner=>" + paramEmailLearner ) ;
%>
<body onload=xxRzbCallEmail("<%=paramEmailLearner%>")>
</body>
IMPORTANT NOTE: This will be deployed to the $OA_HTML on server, when testing from eBusiness Suite

Overall Flow for business case:

1. The processRequest of Controller will create a Submit Button, as it can't be done using Personalization.
2. In processFormRequest of Controller, when Submit Button is clicked, the value in StandardCheckbox will go into the corresponding View Object Attribute
3. We will loop for those records and calculate Concatenated Email String strEmailStringLearner
4. On Submission of Page, we will call xxMailOTA.jsp
5. xxMailOTA.jsp will do two things
    a. Invoke MailTo on load of the jsp page
    b. Send the navigation back to the main page

No comments:

Post a Comment