我有一个使用primeFaces的JSF站点。我无法使用P:RemoreCommand从我的javascript中获取任何参数给我的bean。这里是我的代码:无法使用primefaces将参数从JavaScript传递给JSF Bean RemoteCommand
XHTML:
<p:remoteCommand name="scaleLines" actionListener="#{mapBean2.scaleLines}" update="mapPanel"/>
再后来称之为:
map.on('viewreset', function(){
scaleLines({newZoom:'10'});
});
会话范围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始终为空,意味着该参数不会被传递。我有阅读其他帖子,我不明白为什么它不会通过。我也尝试过使用JSF managedBean作为支持bean和一个名为bean的CDI,bOth具有相同的结果。
我正在使用LeafletJS。当按照建议围绕在双引号中时,JavaScript会引发错误TypeError:t.addLayer不是函数。我尝试用单引号括起来:'scaleLines({'name':'newZoom','value':'10'});'。这产生了和以前相同的结果:Bean方法被调用,但NewZoom为null。 – Rhino
其实我从上面的评论中注意到我已经省略了括号。这似乎工作'scaleLines([{'name':'newZoom','value':'10'}]);'' – Rhino