繁体   English   中英

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

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

我无法从我的JavaScript触发bean方法。

myRemote()应该在xhtml中调用primefaces remoteCommand,这应该会触发对bean中的test1()的调用,但这是永远不会执行的。 为什么?

并且警报确实得到显示,因此它在javascript中命中了addListener

我的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>   

从p:remoteCommand调用的bean方法

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

因此,当我单击一个标记时,click事件触发器将被xhtml处理的myRemote()调用,然后应调用bean方法。 并显示警报,因此它在javascript中命中了addListener

立即=“ 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