Sunday, October 23, 2016

Calling Method for every request upon clicking the selected row second time. (Selection Listener/Client Listener/ Server Listener)

Scenario : Suppose there is an af:table with one row. On selecting the row for the first time you want some custom logic to be executed. On selecting the same row for the second time, you want the same custom logic to be executed again.
Selection Listener : We cannot achieve the above scenario by using Selection Listener. Selection Listener is called only once for each row selection. When we try to select the same row for the second time the Selection Listener is not called.
Client and Server Listener : The above scenario can be achieved by using the Client and Server Listener. For each client request the server method in bean is called. Custom logic can be written in the server listener method.

Solution : 
  • Create EO, VO for a table
  • Drag and drop the table from data control on to the page
  • For the table provide the client listener and server listener as below
<table>
.....
<af:clientListener type="click" method="cancelSelection"/>
 <af:serverListener type="selectEvent" method="#{DemoBean.cancelEvent}"/>
..... 
</table>



Server Listener 

Property
Value
type
The event name which is queued in the java script method
method
Provide the bean method name
  
Client Listener 

Property
Value
type
click (In our case we execute on click of table row)
method
Provide the Java Script method name

  • Write the following Java Script in the jspx page (or create a new java script file and include it in the jspx page by using  <af:resource type="javascript" source="<JavaScriptFileName.js>"/>)
 <af:resource type="javascript">
      function cancelSelection(e) {
      var source=e.getSource();
      AdfCustomEvent.queue(source,"selectEvent",{},true);
}</af:resource>



To fire a custom event from the client, use the AdfCustomEvent.queue() Javascript method. The Javascript having AdfCustomEvent.queue() should be called by the ClientListener, and AdfCustomEvent.queue() method is calling the server side action defined in ServerListener.

AdfCustomEvent.queue() method that takes the event source, the string selectEvent as the custom event type, a null parameter map, and true/false value for the immediate parameter.

By giving the client and server listener, the logic in #{DemoBean.cancelEvent} method is executed every time the user clicks on the row. 


Post from  : http://adf-tips-neetika.blogspot.in/2014/09/client-and-server-listener.html

Thanks Neetika Sharma

No comments:

Post a Comment