0 Replies Latest reply on Sep 27, 2011 12:59 PM by ndrw_cheung

    Picklist : valueChangeListener not working

    ndrw_cheung

      Hi, all. I am using RichFaces 3.3.3.Final with JBOSS EPP5.1.1. I have a problem with the valueChangeListener of the picklist. When I move an item from the left hand side of the picklist to the right hand side, the valueChangeListener is not invoked. Here is the code:

       

      In index.xhtml:

       

      <rich:pickList id="pkOffices" sourceListWidth="377px" targetListWidth="377px" showButtonsLabel="false" copyAllVisible="false" removeAllVisible="false"  value="#{myBean.selectedOffices}" converter="sibcvtr" valueChangeListener="#{myBean.markOfficesModified}" immediate="false">

      <f:selectItems value="#{myBean.offices}"/>

      </rich:pickList>

       

      In the bean:

       

      public void markOfficesModified(ValueChangeEvent event) {

                String  officesChanged = (String)event.getNewValue(); 

                _Logger.debug("officesChanged = " + officesChanged);

          

           }

       

       

      Code for the converter:

       

      import javax.faces.component.UIComponent;

      import javax.faces.context.FacesContext;

      import javax.faces.convert.Converter;

       

      import org.apache.log4j.Logger;

       

       

      import demo.SIBean;

       

          public class SIBeanConverter implements Converter {

       

       

              @Override

              public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

                  // TODO Auto-generated method stub

           

                 

                  int index = arg2.indexOf(':');

                  if (index == -1) {

                      return new SIBean(arg2,arg2);         //workaround for index out of range issue (arg2 should contain "label:value"; but sometimes it only contain "value" due to the bug reported in JIRA)

                  }

                  else {

                      return new SIBean(arg2.substring(0, index), arg2.substring(index + 1));

                  }

                 

       

              }

       

              @Override

              public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {

                  // TODO Auto-generated method stub

                  if (arg2 instanceof SIBean) {

                      return ((SIBean)arg2).getLabel() + ":" + ((SIBean)arg2).getValue();

                  }

                  else {

                      return  arg2.toString();

                  }

              }

       

      }

       

      Code in SIBean:

       

      import org.apache.commons.lang.builder.EqualsBuilder;

      import org.apache.log4j.Logger;

       

       

      public class SIBean {

       

          private String label;

          private String value;

         

          public SIBean(String newlabel, String newvalue){

              label = newlabel;

              value = newvalue;

          }

          public SIBean(){

              label = "";

              value = "";

          }

         

          public String getLabel() {

              return label;

          }

          public void setLabel(String label) {

              this.label = label;

          }

          public String getValue() {

              return value;

          }

          public void setValue(String value) {

              this.value = value;

          }

         

          public boolean equals(Object obj) {

             

              if (obj == null)

                  return false;

              if (obj == this)

                  return true;

              if (obj.getClass() != getClass())

                  return false;

       

              SIBean rib = (SIBean) obj;

            

                  return new EqualsBuilder().

                  append(value, rib.value).

                  isEquals();

             

          

          }

       

      }

       

      Any help is appreciated.

       

        -Andrew