js变量传给java,将javascript变量传递给Java bean

I am trying to get coordinates from leaflet map ( javascript) and passing them to my managed bean. In order to send javascript variable to my managed bean, I used the answer here

here is the code I'm using

the JSF :

function onClick(e) {

var ff = e.latlng.lat;

ff2= e.latlng.lng;

document.getElementById("formId:x").value = ff;

document.getElementById("formId:y").value = ff2;

myRemote();

}

The bean :

//....

public int latt;

public int longt;

public void displayLatLong(){

System.out.println("x: " + latt);

System.out.println("y: " + longt);

}

//getters and setters

I'm not getting errors, but the value of latt and longt are always 0.

ps :latt and longt are coordinates of a marker ( leaflet marker)

Edit : as Holger said in his comment, the form was not submitted,so modifying the remoteCommand solved my problem. here are the modifications :

解决方案

You don't need a form and all this stuff.

function onClick(e) {

myRemote([

{ name: 'latt', value: e.latlng.lat },

{ name: 'longt', value: e.latlng.lng }

]);

};

and at server side

Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

String latt = params.get("latt");

String longt = params.get("longt");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值