title: Valuechangelistener Doubt in JSF
body: <p>HI,</p>
  
  <p>Please see the following code:</p>
  
  <pre><code>                &lt;h:selectOneMenu id="countries" value="#{countryBean.selectedCountry}" onchange="submit()
                                      valueChangeListener="#{countryBean.changeCountry}"&gt;
                      &lt;f:selectItems value="#{countryBean.countries }" /&gt;
                  &lt;/h:selectOneMenu&gt;  
  </code></pre>
  
  <p><strong>Backing Bean</strong></p>
  
  <pre><code>public void changeCountry(ValueChangeEvent event){      
      String newValue = (String)event.getNewValue();
      String oldValue = (String)event.getOldValue();
  
      System.out.println("New Value : " + newValue);
      System.out.println("Old Value : " + oldValue);
  
      if ("1".equals(newValue)){
          this.countries = new ArrayList&lt;SelectItem&gt;();
          this.cities.add(new SelectItem("1","Delhi"));
          this.cities.add(new SelectItem("2","Mumbai"));
      }
      if ("2".equals(newValue)){
          this.cities = new ArrayList&lt;SelectItem&gt;();
          this.cities.add(new SelectItem("1","Mossco"));
      }       
  }
  </code></pre>
  
  <p>Please let me know if the implementation is correct. It is working fine. 
  My questions are:</p>
  
  <ul>
  <li>What is the advantage of adding the <em>f:valueChangeListener</em> tag inside the <em>h:selectOneMenu</em> tag. I have used the normal attribute valueChangeListener="#{countryBean.changeCountry}". </li>
  <li>Is it necessary to use <em>onchange="submit()</em> this code to change the values.</li>
  <li>What is difference between writing the custom listeners by implementing the ActionListener interface and just using the attribute in the UIComponent tags (action="methodName").
  Please explain me.</li>
  </ul>