我不能从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事件触发器和myRemote(),然后调用xhtml处理的对象,然后调用bean方法。并且显示了警报,因此它击中了javascript中的addListener。
发布于 2016-11-01 21:00:36
Immediate=“真”解决了我的问题,一切都像预期的那样
<h:form styleClass="simpleformstyle" id="remoteForm">
<p:remoteCommand name="myRemote" actionListener="#{mapBean.test1}" process="@this" immediate="true"/>
</h:form>https://stackoverflow.com/questions/40362083
复制相似问题