2012-10-09 36 views
0

我想在我的JSF-2/Primefaces-3應用程序中獲取經度和緯度。我使用下面的代碼:Action沒有在JSF2-Primefaces3應用程序中調用監聽器

XHTML

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

JAVA SCRIPT

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() 
     }]); 
     } 
    }); 
} 

BEAN

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()沒有被調用。任何線索傢伙?

回答

2

更改簽名到

public void retriveCordinates(ActionEvent event){ 

或剛剛從actionListener變成action

而且

最佳做法是使用get或只爲的getter/setter set前綴,這就是爲什麼我改getCordinates分成retriveCordinates

相關問題