我遵循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中做一些调整,但现在我可以显示一条消息,再次感谢。 –