Friday, March 1, 2024

Oracle ADF: Running Javascript in action listener\Java method

 Use case:

We needed to execute a JavaScript function after a Java method executed by an actionListener on an af:button.

In your page, add an af:button with an actionListener 

<af:button id="lMyApplicationDS" 
     actionListener="#{pageFlowScope.mieApplicazioniBean.onClickLinkApps}">
</af:button>

On you Java method, inside the actionListener, add this code:

FacesContext context = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks = 
 org.apache.myfaces.trinidad.util.Service.getRenderKitService( 
context, ExtendedRenderKitService.class);
 
erks.addScript(context, "YOUR JAVASCRIPT FUNCTION");
 

No comments:

Post a Comment