I am starting with JSF so it might seem very basic. I have a command button that need to call a method to compute a bean value and the I want the new value to be passed as a parameter to a JS function. My first attempt was (I need the new info value in my js function):
<h:commandButton id="searchbtn" value="refresh"
action="#{controller.computeBean}"
onclick="renderGraph('#{screenBean.info}');" >
<f:ajax execute="@this" render="@this" />
</h:commandButton>
The controller is sucessfully called. The button is refreshed so the parameter is updated. But the onClick action happened before the controller action, thus the bean was not rendered yet. So I had to click twice on the button to have the desired output. So I used oncomplete from primeface.
<p:commandButton value="#refreshPF"
action="#{controller.computeBean}"
oncomplete="renderGraph('#{screenBean.info}');"
update="@this">
</p:commandButton>
But now the bean passed in the js function does not update with the new value. I know the action is called because I printed the bean value at the end of executing the controller method. I am not sure what I did wrong but I guess it comes from the update. I someone has some tip that might be helpful I would be very thankful.
Library used: jsf 2.2.13 and primeface 6.1
You may invoke JS code from Java, this execute when the response is rendering. View: https://www.primefaces.org/showcase/ui/misc/requestContext.xhtml
In action method Java you can coding:
PrimeFaces.current().executeScript("alert('This onload script is added from backing bean.')");