0

I wounder the value change listener event is not fired. Also, I tried f:valueChangeListener and never get the event fired.

I'm using primefaces 5.3

Any Help, Please.

-- Here is the form

<h:form id = "templatelocal_id" name="templatelocal_form">
    <ul>
        <li>
            <h:selectOneMenu 
                id="locale_menu_id" 
                value="#{localizationBean.selectedLocalName}"
                valueChangeListener="#{localizationBean.changeLanguage}"  
                onchange="submit()">
                <f:selectItems 
                    var="c" 
                    value="#{localizationBean.localsList}"
                    itemLabel="#{c.displayLanguage}" 
                    itemValue="#{c.displayLanguage}" />
            </h:selectOneMenu> 
        </li>
    </ul>
</h:form>

Here is the backing bean.

  • List item

    @ManagedBean(name="localizationBean")
    @SessionScoped
    public class LocalizationBean {
    
       private Locale locale;
    
       private Locale selectedLocalName;
    
       private List<Locale> localsList = new ArrayList<Locale>();
    
       public LocalizationBean()
       {
           System.out.println("--------");
       }
    
       @PostConstruct
           public void init() 
           {
               System.out.println("--------Init");
    
               locale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
    
               localsList.add(locale);
               Iterator<Locale> lsList = FacesContext.getCurrentInstance().getApplication().getSupportedLocales();
    
               while (lsList.hasNext()) {
                   Locale currentLocale = lsList.next();
                   localsList.add(currentLocale);
               }
           }
    
       public void changeLanguage(ValueChangeEvent e)
       {
           System.out.println("--------change");
    
           Object newValue = e.getNewValue();
           System.out.println("-----------" + newValue);
       }
    
       public Locale getLocale() 
       {
           return locale;
       }
    
       public String getLanguage() 
       {
           return locale.getLanguage();
       }
    
       public void setLanguage(String language) 
       {
           locale = new Locale(language);
           FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
       }
    
       public Locale getSelectedLocalName() {
           return selectedLocalName;
       }
    
       public void setSelectedLocalName(Locale selectedLocalName) {
           this.selectedLocalName = selectedLocalName;
       }
    
       public List<Locale> getLocalsList() {
           return localsList;
       }
    
       public void setLocalsList(List<Locale> localsList) {
           this.localsList = localsList;
       }
    
    }
    
mszymborski
  • 1,615
  • 1
  • 20
  • 28
Farag Zakaria
  • 178
  • 1
  • 9
  • What does `onchange="submit()"` do? And remove `primefaces` tag, there is no PrimeFaces in your code. – Geinmachi Aug 14 '16 at 11:05
  • 2
    First of all have a look at [this answer](http://stackoverflow.com/a/2120183/3736575). You are using a complex object type, adding a propper converter may help you. – irieill Aug 14 '16 at 11:30

0 Answers0