我有一個使用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