Friday 12 June 2015

OAF: How to Capture LOV event in Oracle Application Framework

In this post I will show a sample code to capture the LOV event in processFormRequest of controller in OA Framework.

To get the source LOV ID, you could use 2 methods.

  • pageContext.getLovInputSourceId();(This method cannot be used to get the lovInputsourceId, if the LOV is inside a table/advancedTable region and you want to use this value to get the return Items using getLovResultsFromSession() .) 
  • pageContext.getParameter(SOURCE_PARAM);(This method will not return the exact lov Id when the lov is placed inside a table/advanced table region. Refer the last section for details.)





To handle the lov event (IdLov) in the above page structure, use the below code:
 if(pageContext.isLovEvent())  
 {  
      String lovInputSourceId = pageContext.getLovInputSourceId();  
      if("IdLov".equals(lovInputSourceId)) {  
           System.out.println("Inside isLovEvent of IdLov");  
      }  
 }  

If you want to get the return values from the lov (if the lov is not inside a table/advancedTable) you can use the below code. If the lov is inside table/advancedTable, Refer the last section.
 import java.util.Hashtable;  
 import java.util.Enumeration;  
 if(pageContext.isLovEvent())  
 {   
      String lovInputSourceId = pageContext.getLovInputSourceId();  
      if("IdLov".equals(lovInputSourceId)) {  
           System.out.println("Inside isLovEvent of IdLov");  
           Hashtable lovResults = pageContext.getLovResultsFromSession(lovInputSourceId);  
           if(lovResults!=null)  
           {  
                String userId =(String)lovResults.get("IdLov"); // "IdLov" is the Return Item specified in the lovMap  
                System.out.println("userId:" + userId);  
                  
                // To get all the Return Values the below code can be used
                Enumeration e = lovResults.keys();  
                while (e.hasMoreElements()) {  
                     String key  = (String) e.nextElement();  
                     String value = (String)lovResults.get(key);  
                     System.out.println(key + " : " + value);  
                }  
           }  
      }  
 }  

If you need to handle specific events on the LOV, the following options are also available.

When you enter a correct value in the Lov and tab out, the lov Windows will not popup. The above code works fine in this scenario. Along with that there is one more event which gets fired  'lovValidate'.
 if(pageContext.isLovEvent())  
 {   
      String lovEvent = pageContext.getParameter(EVENT_PARAM);  
      if("lovValidate".equals(lovEvent)) {  
           String lovInputSourceId = pageContext.getLovInputSourceId();  
           if("IdLov".equals(lovInputSourceId)) {  
                System.out.println("Inside isLovEvent of IdLov");  
           }  
      }  
 }  

When you click on the torch icon, the isLovEvent() returns false. But to handle this event you can use 'lovPrepare'.
 if("lovPrepare".equals(lovEvent)) {  
      String lovInputSourceId = pageContext.getLovInputSourceId();  
      if("IdLov".equals(lovInputSourceId)) {  
           System.out.println("Inside Lov Prepare of IdLov");  
      }  
 }  

When you select a value from the LOV popup, 'lovUpdateevent gets fired. isLovEvent() returns true in this case.
 if(pageContext.isLovEvent())  
 {   
      String lovEvent = pageContext.getParameter(EVENT_PARAM);  
      if("lovUpdate".equals(lovEvent)) {  
           String lovInputSourceId = pageContext.getLovInputSourceId();  
           if("IdLov".equals(lovInputSourceId)) {  
                System.out.println("Inside isLovEvent of IdLov");  
           }  
      }  
 }  

If the LOV is inside a table/advancedTable region the SOURCE_PARAM will return <region>:<lov_Item_id>:<row_num>.This is because the uniqueId of the field gets generated dynamically when the page gets loaded.  
 if(pageContext.isLovEvent())  
 {   
      String lovInputSourceId = pageContext.getParameter(SOURCE_PARAM);
      // In this example lovInputSourceId comes as 'AdvancedTableRN:EmailLov:0'
      if(lovInputSourceId != null && lovInputSourceId.contains(":EmailLov:")) {  
           System.out.println("Inside isLovEvent of EmailLov from AdvancedTable");  
      }
      lovInputSourceId = pageContext.getLovInputSourceId();
      // In this example lovInputSourceId comes as 'EmailLov'  
 }  

If you want to get the return values from the lov when the lov is inside a table/advancedTable, you can use the below code. This code will work for the normal lov also. 
 import java.util.Hashtable;  
 import java.util.Enumeration;  
 if(pageContext.isLovEvent())  
 {   
      String lovInputSourceId = pageContext.getLovInputSourceId();  
      if("EmailLov".equals(lovInputSourceId)) {  
           System.out.println("Inside isLovEvent of EmailLov from AdvancedTable");  
           Hashtable lovResults = pageContext.getLovResultsFromSession(pageContext.getParameter(SOURCE_PARAM));  
           if(lovResults!=null)  
           {  
                String emailAddress =(String)lovResults.get("EmailLov"); // "EmailLov" is the Return Item specified in the lovMap  
                System.out.println("emailAddress:" + emailAddress);  
                  
                // To get all the Return Values the below code can be used
                Enumeration e = lovResults.keys();  
                while (e.hasMoreElements()) {  
                     String key  = (String) e.nextElement();  
                     String value = (String)lovResults.get(key);  
                     System.out.println(key + " : " + value);  
                }  
           }  
      }  
 }  


Feel free to point out if anything is missing/wrong in this blog.

6 comments:

  1. Hello,
    Is there any way to block the lovEvent?
    e.g: suppose i searched in lov first time the lovEvent get fired.
    again i want to update lov value so i searched in lov second time , so i want to block the lovEvent. Is it possible.

    Thank you

    ReplyDelete
    Replies
    1. Sorry, didnt quite understand the requirement.

      Delete
  2. how to get current row of row which contain the lov input whished fire the event in the table

    ReplyDelete
    Replies
    1. Why do you want to get that ? What is your business requirement ?

      Delete
  3. hi,can you tell me how to get the lov value if it is in a separate region? (ex: iProcurement Requisition page --> Manage Approvals). I am extending controller of requisition page and wanted to get the value of Approver selected / changed using manager approvals region.

    ReplyDelete
  4. Hi ,
    I can enter any value in the field containing lov but not within the list of values. Then trying to save it. It got saved.How to perform the validation . The lov are internal lov

    ReplyDelete