简体   繁体   English

jsf使用p:remoteCommand从javascript调用bean方法

[英]jsf calling bean method from javascript using p:remoteCommand

I cant trigger a bean method from my javascript. 我无法从我的JavaScript触发bean方法。

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. myRemote()应该在xhtml中调用primefaces remoteCommand,这应该会触发对bean中的test1()的调用,但这是永远不会执行的。 WHY? 为什么?

And the alert does get displayed so it is hitting the addListener in the javascript 并且警报确实得到显示,因此它在javascript中命中了addListener

my javascript 我的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 的xhtml

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

bean method called from p:remoteCommand 从p:remoteCommand调用的bean方法

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. 因此,当我单击一个标记时,click事件触发器将被xhtml处理的myRemote()调用,然后应调用bean方法。 And the alert is displayed so it is hitting the addListener in the javascript 并显示警报,因此它在javascript中命中了addListener

immediate="true" solved my issue, everything behaves as expected 立即=“ true”解决了我的问题,一切都按预期进行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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