无法使用primefaces RemoteCommand将参数从javascript传递到JSF Bean

无法使用primefaces RemoteCommand将参数从javascript传递到JSF Bean,javascript,jsf,primefaces,Javascript,Jsf,Primefaces,我有一个使用primeFaces的JSF站点。我无法使用P:RemoreCommand从javascript向bean获取任何参数。这是我的密码: xhtml: <p:remoteCommand name="scaleLines" actionListener="#{mapBean2.scaleLines}" update="mapPanel"/> 会话范围的ManagedBean: public void scaleLines(){ String newZoom = F

我有一个使用primeFaces的JSF站点。我无法使用P:RemoreCommand从javascript向bean获取任何参数。这是我的密码:

xhtml:

<p:remoteCommand name="scaleLines" actionListener="#{mapBean2.scaleLines}"  update="mapPanel"/>
会话范围的ManagedBean:

public void scaleLines(){

   String newZoom = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("newZoom");

    if(newZoom == null){
        Logger.getAnonymousLogger().info("Zoom level is null");
    }
    else{
    Integer newZoomInt = Integer.parseInt(newZoom);
    this.mapzoomLevel = newZoomInt;
    for(ZsyMap1Linetest line : allTestLines){
        line.setWeight(((line.getWeight()*newZoomInt)/(6)));
    }
   }
}

这确实调用了该方法,但当我附加一个调试器时,我可以看到newZoom始终为null,这意味着该参数不会被传递。我读过其他帖子,我不明白为什么它不能通过。我还尝试了使用JSF managedBean作为支持bean和CDI命名bean,两者的结果都是相同的。

你能在
scaleLines()的参数周围放一个方括号
[
,就像这样
scaleLines([{newZoom:'10'}])
?另外,请确保
remoteCommand
位于
h:form
中。如果它不起作用,因为我已经很长时间没有使用primefaces了,而且自从上次使用以来已经发生了很多变化,您可以使用传统的方式来通信js和backbean。也就是说,要有一个1个文本字段和1个按钮的隐藏形式,并使用jquery/js将值
10
填充到文本字段的值中。此文本字段应将其值绑定到bean中的
newZoom
变量。然后使用jquery/js单击将触发
scaleLines
方法的命令按钮。如果不必将文本字段绑定到bean上的变量,仍然可以从requestParameterMap获取值
10

问题在于使用了错误的格式。您必须使用带有“name”和“value”的JS对象数组。即
[{“name”:“param1”,“value”:“value1”},…]


在您的情况下,将
scaleLine
的参数更改为
[{“name”:“newZoom”,“value”:“10”}]
应该就可以了。此外,您应该在JS对象中的键周围加上
“”
,否则它就不是有效的JSON。

我正在使用JS。当按照建议用双引号括起来时,javascript抛出错误TypeError:t.addLayer不是函数。我试着用单引号括起来:
scaleLines({'name':'newZoom','value':'10')。这产生了与之前相同的结果:调用了Bean方法,但NewZoom为null。这似乎可以
scaleLines([{'name':'newZoom','value':'10')
public void scaleLines(){

   String newZoom = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("newZoom");

    if(newZoom == null){
        Logger.getAnonymousLogger().info("Zoom level is null");
    }
    else{
    Integer newZoomInt = Integer.parseInt(newZoom);
    this.mapzoomLevel = newZoomInt;
    for(ZsyMap1Linetest line : allTestLines){
        line.setWeight(((line.getWeight()*newZoomInt)/(6)));
    }
   }
}