title: How to call JSF backing bean method using javascript only when The page is loaded
body: <p>The problem is that the back Bean Methode get called many times </p>
  
  <p>well i already read this Answer by  @BalusC </p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/8705614/how-to-call-jsf-backing-bean-method-only-when-onclick-oncomplete-on-event-occ">How to call JSF backing bean method only when onclick/oncomplete/on... event occurs and not on page load</a></p>
  
  <p>so i Understand the why my back been methode get invoked many times,So how i can resolve this  issue</p>
  
  <p>This is my back been Methode </p>
  
  <pre class="lang-java prettyprint-override"><code>@ManagedBean (name="villeBean)"
  @ViewScoped
  public class Villes {
   public String listeVilles{
     return dao.listeVilles();
   }
  }
  </code></pre>
  
  <p>and this is my js Code</p>
  
  <pre class="lang-js prettyprint-override"><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 &gt;= 15){
      localStorage.setItem('date',date);
      localStorage.setItem('ville',#{villeBean.listeVilles()});
    }
  } 
  </code></pre>
  
  <p>The issue is that the back been methode get invoked 2 times </p>