The problem is that the back Bean Methode get called many times
well i already read this Answer by @BalusC
JSF is a server side language which runs on the webserver upon a HTTP request and produces HTML/CSS/JS code which get returned with the HTTP response. All EL expressions in form of ${} and #{} will be executed in the server side during generating the HTML output. JavaScript is a client side language which runs on the webbrowser and works on the HTML DOM tree. The HTML onclick attribute should specify a JavaScript function which will be executed in the client side on the particular HTML DOM event.
so i Understand the why my back been methode get invoked many times,So how i can resolve this issue
This is my back been Methode
@ManagedBean (name="villeBean)"
@ViewScoped
public class Villes {
public String listeVilles{
return dao.listeVilles();
}
}
and this is my js Code
if(localStorage['ville'] == null || localStorage['date']==null){
localStorage.setItem('date',new Date());
localStorage.setItem('ville',#{villeBean.listeVilles()});
}
else{
var oldDate = new Date(localStorage['date']).getTime();;
var currentDate = new Date().getTime();
var distance = currentDate - oldDate ;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
if (days >= 15){
localStorage.setItem('date',date);
localStorage.setItem('ville',#{villeBean.listeVilles()});
}
}
The issue is that the back been methode get invoked 2 times