4 Replies Latest reply on May 30, 2013 2:47 PM by ganesh singh

    valueChangeListener not working

    ganesh singh Newbie

      Hi All

       

      i have a problem. I try this example and its doesn't worked, http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=ajax&sample=selectsUpdates&skin=blueSky.

       

      In this code is one valuechangelistener and it doesn't worked fine.

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"

          xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"

          xmlns:rich="http://richfaces.org/rich">

          <h:form>

              <h:selectOneMenu value="#{selectsBean.currentType}" valueChangeListener="#{selectsBean.valueChanged}">

                  <f:selectItems value="#{selectsBean.firstList}" />

                  <a4j:ajax event="valueChange" render="second" execute="@this" />

              </h:selectOneMenu>

              <a4j:outputPanel id="second" layout="block">

                  <h:selectOneMenu value="#{selectsBean.currentType}" rendered="#{not empty selectsBean.currentType}">

                      <f:selectItems value="#{selectsBean.secondList}" />

                  </h:selectOneMenu>

              </a4j:outputPanel>

          </h:form>

      </ui:composition>

       

       

      can any one help me out, thanks in advanced

        • 1. Re: valueChangeListener not working
          Juraj Húska Master

          Hello Ganesh,

           

          two things:

          1. Are you sure that your complete facelet you are using has h:head and h:body tags where it is all nested ? Like it is done in the template for the demo in showcase here:

          https://github.com/richfaces/richfaces/blob/master/examples/showcase/src/main/webapp/templates/main.xhtml

           

          2. Are you sure that your backing bean is correct ?

           

          Nevertheless I would like to recommend you to start with the richfaces archetypes to gain some experience. Look at developer guide how to do it:

          http://www.jboss.org/richfaces/docs

          • 2. Re: valueChangeListener not working
            iabughosh Master

            hello ganesh,

            you need to modify a4j:ajax event to this :

            <a4j:ajax event="change" render="second" execute="@this" />

             

            regards.

            • 3. Re: valueChangeListener not working
              ganesh singh Newbie

              Hi all,

               

              Thank's for your reply Ibrahim & Juraj,

               

              Ibrahim i try your suggestion before but it can't work for me,

               

              What i notice is that event is not fired while changing value in selectItems.

               

              List of jar which i am using

               

              1. cssparser-0.9.5.jar

              2. guava-10.0.1.jar

              3. javax.faces-2.1.5.jar

              4. jaxb-api.jar

              5. richfaces-components-api-4.3.2.Final.jar

              6. richfaces-components-ui-4.3.2.Final.jar

              7. richfaces-core-api-4.3.2.Final.jar

              8. richfaces-core-impl-4.3.2.Final.jar

              9. sac-1.3.jar

               

               

              Bleow is my bean class.

               

              package com.dw;

               

              import java.util.ArrayList;

              import java.util.List;

               

              import javax.faces.bean.ManagedBean;

              import javax.faces.bean.RequestScoped;

              import javax.faces.event.ValueChangeEvent;

              import javax.faces.model.SelectItem;

              import java.io.Serializable;

               

              /**

              * @author Ilya Shaikovsky

              */

              @ManagedBean(name = "selectsBean")

              @RequestScoped

              public class SelectsBean{

                  private static final String[] FRUITS = { "", "Banana", "Cranberry", "Blueberry", "Orange" };

                  private static final String[] VEGETABLES = { "", "Potatoes", "Broccoli", "Garlic", "Carrot" };

                  private String currentItem = "";

                  private String currentType = "";

                  private List<SelectItem> firstList = new ArrayList<SelectItem>();

                  private List<SelectItem> secondList = new ArrayList<SelectItem>();

               

                  public SelectsBean() {

               

                         SelectItem item = new SelectItem("", "");

               

                      firstList.add(item);

                      item = new SelectItem("fruits", "Fruits");

                      firstList.add(item);

                      item = new SelectItem("vegetables", "Vegetables");

                      firstList.add(item);

               

                      for (int i = 0; i < FRUITS.length; i++) {

                          item = new SelectItem(FRUITS[i]);

                      }

               

              }

               

                  public List<SelectItem> getFirstList() {

                      return firstList;

                  }

               

                  public List<SelectItem> getSecondList() {

                      return secondList;

                  }

               

                  public static String[] getFRUITS() {

                      return FRUITS;

                  }

               

                  public static String[] getVEGETABLES() {

                      return VEGETABLES;

                  }

               

                  public void valueChanged(ValueChangeEvent event) {

                            secondList.clear();

                      if (null != event.getNewValue()) {

                          String[] currentItems;

               

                          if (((String) event.getNewValue()).equals("fruits")) {

                              currentItems = FRUITS;

                          } else {

                              currentItems = VEGETABLES;

                          }

               

                          for (int i = 0; i < currentItems.length; i++) {

                              SelectItem item = new SelectItem(currentItems[i]);

               

                              secondList.add(item);

                          }

                      }

                  }

               

                  public String getCurrentType() {

                      return currentType;

                  }

               

                  public void setCurrentType(String currentType) {

                      this.currentType = currentType;

                  }

               

                  public String getCurrentItem() {

                      return currentItem;

                  }

               

                  public void setCurrentItem(String currentItem) {

                      this.currentItem = currentItem;

                  }

              }

              • 4. Re: valueChangeListener not working
                ganesh singh Newbie

                Hi All,

                 

                Thank's it's working now.