Primefaces Java <-> Javascript

Calling java method from javascript

1
2
3
4
5
6
7
8
<p:remoteCommand name="increment" actionListener="#{counter.increment}" 
out="count" />

<script type="text/javascript">
function customfunction() {
increment(); // Call increment method from counter bean based on remoteCommand name
}
</script>

Calling javascript from java

1
2
3
public void callJavascript() {
RequestContext.getCurrentInstance().execute("refresh();");
}