4 Replies Latest reply on Apr 24, 2008 8:36 PM by sergeysmirnov

    Combobox / Listener Question

    red247

      I have been trying to get a listener to work for a richfaces combobox using SEAM.

      The following is the combobox code, which is trying to trigger the listener:

      <aj4:region id="selectView" rerender="treeView">
       <h:form>
       <rich:comboBox
       id="selectedView"
       value="#{display.state}"
       onSelect="this.form.submit()"
       valueChangeListener="#{display.switchView}"
       reRender="treeView">
       <f:selectItem itemValue="Alarms"/>
       <f:selectItem itemValue="Alarm Definitions"/>
       <f:selectItem itemValue="Locations"/>
       </rich:comboBox>
       </h:form>
      </aj4:region>
      
      


      The next set of code is the EJB interface, which defines the method to catch the event.

      
      import javax.ejb.Local;
      import javax.faces.event.ValueChangeEvent;
      
      @Local
      public interface Display {
      
       public void display();
      
       public void destroy();
      
       public String getState();
       public void setState(String state);
      
       public void switchView(ValueChangeEvent event);
      
      }
      
      


      Then the remainder is the bean implementation to handle the event.


      
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.faces.event.ValueChangeEvent;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.log.Log;
      
      @Stateful
      @Name("display")
      @Scope(ScopeType.SESSION)
      public class DisplayBean implements Display {
      
       private static final String DEFAULT_VIEW_STATE = "Locations";
      
       @Logger
       private Log log;
      
       @In
       FacesMessages facesMessages;
      
      // private String value;
       private String state = DEFAULT_VIEW_STATE;
      
       public void display()
       {
       //implement your business logic here
       log.info("display.display() action called with: #{display.value}");
       facesMessages.add("display #{display.value}");
       }
      
       public String getState(){
       return state;
       }
      
       public void setState( String state ){
       this.state = state;
       }
      
       @Destroy @Remove
       public void destroy() {}
      
      
       public void switchView(ValueChangeEvent event) {
       log.info("listener triggered");
       log.info("New value: " + event.getNewValue().toString() );
       }
      
      }
      
      


      When the page is rendered, the combobox and the rest of the display show up properly. But when I select a different value, nothing happens. Any help you could provide would be greatly appeciated.

      Regards,

      M.

        • 1. Re: Combobox / Listener Question
          red247

          I'm currently using RichFaces 3.2.0.SR1 and JBoss 4.2.2.GA

          • 2. Re: Combobox / Listener Question

             

            "red247" wrote:
            I have been trying to get a listener ...
            <aj4:region id="selectView" rerender="treeView">
             <h:form>
             <rich:comboBox
             id="selectedView"
             value="#{display.state}"
             onSelect="this.form.submit()"
             valueChangeListener="#{display.switchView}"
             reRender="treeView">
             <f:selectItem itemValue="Alarms"/>
             <f:selectItem itemValue="Alarm Definitions"/>
             <f:selectItem itemValue="Locations"/>
             </rich:comboBox>
             </h:form>
            </aj4:region>
            
            



            Looks like you rely on magic while programming.

            1. aj4:region -> a4j:region
            2. a4j:region does NOT have rerender attribute
            3. rich:comboBox does NOT have reRender attribute
            4. rich:comboBox is NOT a standard html form element. ie it does NOT have a this.form object.

            So, it is not about the listener yet. This code just does not send any Ajax request.

            • 3. Re: Combobox / Listener Question
              red247

              I just started using SEAM a couple of days ago, so I know enough to be dangerous at this point. Thanks for the pointer!!

              • 4. Re: Combobox / Listener Question

                 

                "red247" wrote:
                I just started using SEAM a couple of days ago, so I know enough to be dangerous at this point. Thanks for the pointer!!


                It is not about the Seam yet. You have a problem with the page. You need to learn this stuff as well. ..and do not rely on magic. It rarely works in JSF.