【问题标题】:Action Listener not being called in JSF2-Primefaces3 application在 JSF2-Primefaces3 应用程序中未调用动作侦听器
【发布时间】:2012-10-09 09:59:19
【问题描述】:

我正在尝试在我的 JSF-2/Primefaces-3 应用程序中获取纬度和经度。我正在使用以下代码:

XHTML

<h:inputText id="address" value="#{nyBean.address}" />
<p:remoteCommand name="rmtCommandGeocoder" actionListener="#{myBean.getCordinates}" />

JAVA 脚本

function geocoder() {
   var geocoder = new google.maps.Geocoder();
   var address = document.getElementById("address").value;
   geocoder.geocode({
      'address' : address
   }, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
         // Calls the remoteCommand "rmtCommandGeocoder",
         // passing the coordinates to map of parameters
         rmtCommandGeocoder([ {
            name : 'latitude',
            value : results[0].geometry.location.lat()
         }, {
            name : 'longitude',
            value : results[0].geometry.location.lng()
         }]);
      }
   });
}

public void getCordinates() {
   FacesContext context = FacesContext.getCurrentInstance();
   Map<String, String> parameterMap = context.getExternalContext().getRequestParameterMap();
   double latitude = Double.parseDouble((String) parameterMap.get("latitude"));
   double longitude = Double.parseDouble((String) parameterMap.get("longitude"));
}

这里的问题是 getCordinates() 没有被调用。有什么线索吗?

【问题讨论】:

    标签: jsf jsf-2 google-maps-api-3 primefaces


    【解决方案1】:

    把签名改成

    public void retriveCordinates(ActionEvent event){
    

    或者只是从 actionListener 更改为 action

    还有

    最佳实践是仅对 getter/setter 使用 getset 前缀,这就是我将 getCordinates 更改为 retriveCordinates 的原因

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 2012-06-07
      • 2019-01-21
      • 1970-01-01
      • 2012-04-30
      • 2012-04-21
      • 2019-07-25
      • 2019-01-26
      相关资源
      最近更新 更多