5 Replies Latest reply on Nov 13, 2007 8:26 AM by Mauro T

    a4j and selectOneMenu's valueChangeListener

    Mauro T Newbie

      Hi all,

      I'm just building an simple application that loads some items inside a selectOneMenu when a onblur event occurs in a inputText.So far everything is going well.
      The problem starts when a try to add a valueChangeListener to the selectOneMenu and also add a a4j support linked to onChange event.
      When I reproduce the onblur event for the second time OR when I change the combo value an java.util.NoSuchElementException is throwed.

      Can you help me ?

      Thats the cursed code ;-)

      
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
      
      
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
      <title>Insert title here</title>
      </head>
      <body>
      
      <f:view>
       <h:form id="form">
      
       <rich:panel style="border:none" id="parent">
      
       <h:inputText value="#{testeForm.inputText}">
       <a4j:support event="onblur" actionListener="#{testeForm.loadItems}"
       reRender="parent">
       </a4j:support>
       </h:inputText>
      
      
       <h:selectOneMenu valueChangeListener="#{testeForm.change}" value="#{testeForm.id}">
       <a4j:support event="onchange"></a4j:support>
       <f:selectItems value="#{testeForm.items}" />
       </h:selectOneMenu>
      
       </rich:panel>
      
       </h:form>
      </f:view>
      </body>
      </html>
      


      public class TesteForm {
      
       private List<SelectItem> items;
       private String inputText;
       private Integer id;
      
      
       @PostConstruct
       public void init(){
       items = new ArrayList<SelectItem>();
       }
      
       public List<SelectItem> getItems() {
       return items;
       }
      
       public void setItems(List<SelectItem> items) {
       this.items = items;
       }
      
      
      
       public Integer getId() {
       return id;
       }
      
       public void setId(Integer id) {
       this.id = id;
       }
      
       public String getInputText() {
       return inputText;
       }
      
       public void setInputText(String inputText) {
       this.inputText = inputText;
       }
      
       public void loadItems(ActionEvent event) {
       for (int x = 0; x < 5; x++){
       items.add(new SelectItem(x,x+""));
       }
       }
      
       public void change(ValueChangeEvent changeEvent) {
       System.out.println("HELLO");
       }
      
      
      }
      
      
      


        • 1. Re: a4j and selectOneMenu's valueChangeListener
          Mauro T Newbie

          Somebody ?

          "trajber" wrote:
          Hi all,

          I'm just building an simple application that loads some items inside a selectOneMenu when a onblur event occurs in a inputText.So far everything is going well.
          The problem starts when a try to add a valueChangeListener to the selectOneMenu and also add a a4j support linked to onChange event.
          When I reproduce the onblur event for the second time OR when I change the combo value an java.util.NoSuchElementException is throwed.

          Can you help me ?

          Thats the cursed code ;-)
          
          
          <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
          <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
          
          
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
          <title>Insert title here</title>
          </head>
          <body>
          
          <f:view>
           <h:form id="form">
          
           <rich:panel style="border:none" id="parent">
          
           <h:inputText value="#{testeForm.inputText}">
           <a4j:support event="onblur" actionListener="#{testeForm.loadItems}"
           reRender="parent">
           </a4j:support>
           </h:inputText>
          
          
           <h:selectOneMenu valueChangeListener="#{testeForm.change}" value="#{testeForm.id}">
           <a4j:support event="onchange"></a4j:support>
           <f:selectItems value="#{testeForm.items}" />
           </h:selectOneMenu>
          
           </rich:panel>
          
           </h:form>
          </f:view>
          </body>
          </html>
          


          public class TesteForm {
          
           private List<SelectItem> items;
           private String inputText;
           private Integer id;
          
          
           @PostConstruct
           public void init(){
           items = new ArrayList<SelectItem>();
           }
          
           public List<SelectItem> getItems() {
           return items;
           }
          
           public void setItems(List<SelectItem> items) {
           this.items = items;
           }
          
          
          
           public Integer getId() {
           return id;
           }
          
           public void setId(Integer id) {
           this.id = id;
           }
          
           public String getInputText() {
           return inputText;
           }
          
           public void setInputText(String inputText) {
           this.inputText = inputText;
           }
          
           public void loadItems(ActionEvent event) {
           for (int x = 0; x < 5; x++){
           items.add(new SelectItem(x,x+""));
           }
           }
          
           public void change(ValueChangeEvent changeEvent) {
           System.out.println("HELLO");
           }
          
          
          }
          
          
          


          • 2. Re: a4j and selectOneMenu's valueChangeListener
            Ilya Shaikovsky Master

            checked with 3.2.0 SNAPSHOT jsf 1.2, Facelets 1.1.14 with the code copied from your post. Any errors. ValueChange listener called a few times when select value changed..

            • 3. Re: a4j and selectOneMenu's valueChangeListener
              Mauro T Newbie

              Thanks for your reply .

              The problem happens when the managed bean scope is "request". There is any way to do that using request scope ?

              "ilya_shaikovsky" wrote:
              checked with 3.2.0 SNAPSHOT jsf 1.2, Facelets 1.1.14 with the code copied from your post. Any errors. ValueChange listener called a few times when select value changed..


              • 4. Re: a4j and selectOneMenu's valueChangeListener
                Dmitry Demyankov Novice

                Use a4j:keepAlive with your request scope bean.

                • 5. Re: a4j and selectOneMenu's valueChangeListener
                  Mauro T Newbie

                  Thanks both of you.It works using keepAlive.

                  "dmitry.demyankov" wrote:
                  Use a4j:keepAlive with your request scope bean.