2 Replies Latest reply on Apr 20, 2010 10:14 AM by Cris Grama

    valueChangeListener reacting only on second try?

    Cris Grama Newbie

      Hello all,


      I have two drop down lists and I want to load the second one with values based on what was chosen in the first one. However, the onchange event is only detected the second time I change the selection!


      The relevant bits of the xhtml:



      <ui:define name="body">
      <h:form>
      <h:panelGrid columns="2">
          <rich:inplaceSelect value="#{searchSimilarProblems.problematicArea}" 
             valueChangeListener="#{searchSimilarProblems.problematicAreaValueChanged}" defaultLabel="Click here to select">
              <f:selectItems value="#{searchSimilarProblems.problematicAreas}"/>
              <a4j:support event="onchange" reRender="items"/>
          </rich:inplaceSelect>
          <a4j:outputPanel id="label">
              <h:outputText value="Choose concrete product:" />
          </a4j:outputPanel>  
          <a4j:outputPanel id="items">
              <rich:inplaceSelect value="#{searchSimilarProblems.impactedElement}" defaultLabel="Click here to select">
                  <f:selectItems value="#{searchSimilarProblems.impactedElements}"/>
              </rich:inplaceSelect>
          </a4j:outputPanel>
      </h:panelGrid>
      </h:form>
      </ui:define>
      




      And in my bean I have



      public void problematicAreaValueChanged(ValueChangeEvent event)





      The problem is that problematicAreaValueChanged() is invoked only when I modify the value of the problematic area for the second time (and I get a null for the event's oldValue).


      Does anyone have an idea regarding what might be wrong? Thanks in advance! I am using Seam 2.2.0 and Java 1.6.0.19, if that helps.
      --Cristina.

        • 1. Re: valueChangeListener reacting only on second try?
          Gabor Jakab Newbie

          Hi,


          I think a valueChangeListener is not what you want to use here. Read more about it e.g. here...


          But you already have an


          <a4j:support event="onchange" reRender="items"/>



          try to update your model by this event like:


          <a:support event="onchange" 
              action="#{yourBean.yourMethod()}" 
              reRender="items"  
              ajaxSingle="true" 
              eventsQueue="yourQ"
              requestDelay="100"/>

          • 2. Re: valueChangeListener reacting only on second try?
            Cris Grama Newbie

            Thanks for the suggestion! I will try it out.


            In the meantime I managed to make it do what I need by using the event onviewactivated. (With event onchange, it seemed like the event's newValue was constantly one step behind: I had two choices in my first drop down list, when I chose 1, newValue was still 2, then I chose 2 and newValue would become 1, then choosing 1 again made newValue become 2 and so on...)