Amazon Contextual Product Ads

Tuesday, 17 May 2011

Adding Client Side code to Oracle Framework Page

I had to add very simple logic into existing Framework page. One this page 2 checkboxes exists. Lets call one of them “first” and second one will be “second”. Desired result – whenever user clicking on “first” it should disable “second” checkbox. Well first of all I tried to do it on the server side. To do it , I had to submit the page when user clicking on “first” checkbox. This is not a problem. Just choose proper options in the GUI element as you can see in the picture bellow

image.axd

So, user clicking on the checkbox and submitting the page to the server. It is important to give some name in the event field.

Second step is to catch this event inside the controller. User can catch this event in processFormRequest method

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
   super.processFormRequest(pageContext, webBean);    
   if ("submitByfirst".equals(pageContext.getParameter(EVENT_PARAM)))
   {
     //do your logic here
   }
}

Well, I thought that I am one step of achieving the goal. The last think that I should do is to get a reference to “second” checkbox and disable it in the following way



OAMessageCheckBoxBean oaCheckBoxBean = (OAMessageCheckBoxBean) webBean.findIndexedChildRecursive("second");
oaCheckBoxBean.setDisabled(true);

And so I did. And it didn’t work at all!!!  Instead I got an error message saying "blah.. blah.. blah.. You can not do it in processFormRequest method. Nice. The only other place I could do this logic is inside processRequest method. But I can catch my event only in processFormRequest methos. Why Oracle did it in this way?? Who knows.


  Any way if I wanted to proceed this this approach I had to resubmit the page by using pageContext.forwardImmediately() to the same page and then I could proceed my code in processRequest method. I am thinking that it is too much. So I decided to write client code and attach it to the “first” checkbox.


First of all it need to written in the “processRequest” method. Only several lines of code



public void processRequest(OAPageContext pageContext, OAWebBean webBean)
  {
    super.processRequest(pageContext, webBean);
  
      String onClick = "if (this.checked) { document.getElementById('second').disabled =true;}";
  
      OAMessageCheckBoxBean chkEnableOmpact = (OAMessageCheckBoxBean) webBean.findIndexedChildRecursive("first");
      chkEnableOmpact.setOnClick(onClick);
   }
And this is all!!!  Just write your script and attach it to the relevant event.

No comments:

Post a Comment