我遵循Primefaces展示地理編碼功能與p:gmap,如果我把一個真實的地址,沒關係,但如果我把一個無效的地址沒有任何反應,我只收到消息Chrome控制檯「找不到地理編碼」,但我必須趕上事件,以便我可以向用戶顯示自定義消息。Gmap Primefaces Geocode自定義錯誤消息
看得更深我在Primefaces庫裏找到了gmap.js,並且啓動了一個Primefaces.error(「找不到Geocode」),但是我仍然有這個問題,我怎麼能夠捕捉到這個問題?
進出口使用Primefaces 5.2
<p:gmap
widgetVar="w_gmap_edit"
id="gmapId_edit"
center="#{tiendasController.centerGeoMap}"
zoom="15"
type="ROADMAP"
style="width:400px;height:450px"
model="#{tiendasController.mapModel}"
onPointClick="handlePointClick_edit(event)"
>
<p:ajax
event="geocode"
listener="#{tiendasController.onGeoCodeAction}"
onstart="onCompleteGeoCodeEdit(xhr, status, args)"
update="@this center-form:tiendas-editar-latitud-value center-form:tiendas-editar-longitud-value"
/>
</p:gmap>
以及JavaScript函數:
function geocode_edit() {
PF('w_gmap_edit').geocode(document.getElementById('center-form:tiendas-editar-direccion-value').value);
}
感謝Mehdi的迴應,我嘗試了它,但總是執行else塊,無論地址是否正常,就好像函數總是返回false。 –
@JorgeDominguez我找到了解決方案,我編輯了我的答案,並用上面的代碼捕獲了錯誤。祝你好運再次 –
嗨@MehdiBouzidi,非常感謝,它的工作原理,唯一的事情就是p:ajax中的goecode事件不會執行,所以我必須在javascript中做一些調整,但現在我可以顯示一條消息,再次感謝。 –