Tuesday, February 15, 2011

Calling MethodBinding/WebService on Client Event... by converting it to Server Event .

There are so many cases where a method binding and/or web service needs to be called on a client event. When working with ADF rich faces components lots of component do not have properties to capture client event. However ADF does provides ClientListener and ServerListener that can be used to achieve the same. As we know using JavaScript may not be the best solution recommended but when nothing else works, this approach may come handy.

This workaround is extracted from the one of the works by Andrejus in his post related to Custom LOV Type. So in this blog I will to compile how can we do the same. You can download the sample application here.

Test case we are trying to achieve is when user clicks on af:image component we call a bean method and inside this bean method we call a method binding.

1. In an Oracle Fusion Application create a jspx page (say RunMe.jspx). Drag and drop an af:image component on the page. Provide the values for property Source and Short Desc.




2. Right Click on the Web Content folder of the View-Controller project and select New. In the New Gallery wizard select Web Tier, HTML and then select JavaScript Files in Items section and click ok.


 3. Add following method to it.


4. Create a bean and add a method to it like below.


5. Register bean to adfc-config.xml as shown.



6. Click on the jspx and go to the Structure window. Drag and drop af:resource inside the af:document and select Type as 'javascript' and for Source provide the name of java script file.




7. Drag and Drop Client Listener and Server Listener inside af:image component and set the property as shown.





8. Run the jspx (RunMe.jspx) and test the server log. Since we just an image when we run the jspx we see something like




Clicking on the image now invokes an client event which is caught by clientListener and which call the Javascript method. This method raises and server event which is caught by ServerListener and which inturn invokes an bean method as handler. Inside this bean we can call webservice/or method binding or perform any logic we want.

Since we just have an system output we can see that bean method is called on the click event.



No comments:

Post a Comment