Search code examples
javascriptjsfgoogle-maps-api-3primefacesremotecommand

jsf calling bean method from javascript using p:remoteCommand


I cant trigger a bean method from my javascript.

the myRemote() should be calling the primefaces remoteCommand in the xhtml which should be triggering a call to test1() in the bean, but this is NEVER executing. WHY?

And the alert does get displayed so it is hitting the addListener in the javascript

my javascript

function loadMarkers(m) {

    for (var i = 0; i < m.length; i++) {
        PF('w_gmap').addOverlay(m[i]);

        //add listener for event clicking on marker
        google.maps.event.addListener(m[i], 'click', function () {  

            myRemote();  //should be handled by p:remoteCommand
            alert("HI 123");
        }); 
    }   
}

xhtml

<h:form styleClass="simpleformstyle" id="remoteForm">
    <p:remoteCommand name="myRemote" actionListener="#{mapBean.test1}" process="@this"/>
</h:form>   

bean method called from p:remoteCommand

public void test1(){
    System.out.println("HIIIIIIIIIIII");
}

So when i click on a marker, the click event triggers and the myRemote() should be called which the xhtml handles and then should be calling the bean method. And the alert is displayed so it is hitting the addListener in the javascript


Solution

  • immediate="true" solved my issue, everything behaves as expected

    <h:form styleClass="simpleformstyle" id="remoteForm">
        <p:remoteCommand name="myRemote" actionListener="#{mapBean.test1}" process="@this"  immediate="true"/>
    </h:form>