简体   繁体   中英

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM