I want to run a javascript function when I click on a commandButton on signin.xhtml, but when I click on it, a redirection occur to dev.xhtml. I don't want this redirection, I want to stay on signin.xhtml. Actually it's not really a redirection because it's the same index.xhtml page but with lazy loading.
Here my commandButton from signin.xhtml :
<h:form id="formSignInPartner" enctype="multipart/form-data">
<p:commandButton value="Géolocaliser mon commerce" onclick="getLocation()"/>
</h:form>
And index.xhtml :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:pm="http://primefaces.org/mobile"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view renderKitId="PRIMEFACES_MOBILE" />
<h:head>
<script type="text/javascript" src="../javascript/geolocalisationPartner.js"></script>
</h:head>
<h:body>
<pm:page id="dev" lazy ="false">
<ui:include src="trash/dev.xhtml"/>
</pm:page>
<pm:page id="partnerSignIn" lazy="true">
<ui:include src="/Partner/signIn.xhtml"/>
</pm:page>
</h:body>
</html>
Here the script geolocalisationPartner.js but I don't think It's the problem
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function error(msg) {
alert('Geolocalisation échouée :\n' + msg);
}
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, error, options);
} else {
alert('Votre navigateur\nne supporte pas\nla geolocalisation');
}
}
function showPosition(position) {
var long = position.coords.longitude;
var lat = position.coords.latitude;
$(PrimeFaces.escapeClientId('partnerSignIn:formSignInPartner:idlongitude')).val(long);
$(PrimeFaces.escapeClientId('partnerSignIn:formSignInPartner:idlatitude')).val(lat);
alert('Geolocalisation réussie !');
}
I found the problem. In the javascrip console,I saw my script file was not found, the path was erroneous.