Landister Landister - 1 year ago 213
Ajax Question

Primefaces Ajax calling Javascript

I was wondering if you could call javascript inside of an ajax statment specificlly I am trying to get the following to work.

<p:commandLink id="saveButton" value="Save" >
<p:ajax event="click" actionListener="#{bean.saveButtonPressed()}" />
<p:ajax event="click" actionListener="if(#{cbean.showSaveOverlay}){;}" />

And showSaveOverly gets set inside saveButtonPressed.

Any idea how I would do this?

Answer Source

Use the PrimeFaces-provided RequestContext API.

First normalize your ajax listener:

<p:ajax event="click" actionListener="#{cbean.showSaveOverlay}" />

Then invoke RequestContext#execute() in the action listener method accordingly:

public void showSaveOverlay() {
    if (...) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download