4 Replies Latest reply on Aug 5, 2008 6:37 AM by leelavathic leelavathic

    a4j:support event="onchange" executes when it should not

    Shervin Asgari Master

      Hello.

      I have a selectOneMenu which chooses a State. When the state is chosen then it will populate a list and fill another selectOneMenu according to what you chose on the latter. This works fine.

      The problem is that this is a part of a bigger form, and when I submit the form, it executes the valueChangeListener method and my form action does not run.

      Why is that?

      here is the selectOneMenu code:

      <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Fylke</ui:define>
       <h:selectOneMenu value="#{searchProeveManager.fylke}" border="0" valueChangeListener="#{searchProeveManager.updateKommune}" immediate="true">
       <s:selectItems value="#{fylkeList.resultList}" var="fylke" label="#{fylke.navn}"/>
       <a4j:support event="onchange" reRender="kommuneResultat" ajaxSingle="true" />
       <s:convertEntity/>
       </h:selectOneMenu>
      </s:decorate>
       <s:div id="kommuneResultat">
       <ui:define name="label">Kommune</ui:define>
       <s:decorate template="/layout/display.xhtml">
       <h:selectOneMenu value="#{searchProeveManager.kommune}" border="0">
       <s:selectItems value="#{searchProeveManager.kommuner}" var="kom" label="#{kom.navn}"/>
       </h:selectOneMenu>
       </s:decorate>
       </s:div>
      


      And the whole thing xhtml page if you need it.

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j">
      
       <style>
       .tooltip {
       background-color:#{richSkin.generalBackgroundColor};
       border-width:3px;
       padding:10px;
       }
       </style>
       <rich:simpleTogglePanel label="Søk etter prøver" switchType="ajax">
       <h:form id="searchCriteria" styleClass="edit">
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Fornavn</ui:define>
       <h:inputText id="searchStringFornavn" value="#{searchProeveManager.searchStringFornavn}" />
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space:nowrap">
       Søk på fornavn og mellomavn. * søker på alt.
       </span>
       </rich:toolTip>
       </s:decorate>
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Etternavn</ui:define>
       <h:inputText id="searchStringEtternavn" value="#{searchProeveManager.searchStringEtternavn}" />
       </s:decorate>
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Fødselsnummer</ui:define>
       <h:inputText id="searchStringFodselsnr" value="#{searchProeveManager.searchStringFodselsnr}" />
       </s:decorate>
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Adresse</ui:define>
       <h:inputText id="searchStringAdresse" value="#{searchProeveManager.searchStringAdresse}" />
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space:nowrap">
       Søk på adressen til personen. * søker på alt.
       </span>
       </rich:toolTip>
       </s:decorate>
      
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Fylke</ui:define>
       <h:selectOneMenu value="#{searchProeveManager.fylke}" border="0" valueChangeListener="#{searchProeveManager.updateKommune}" immediate="true">
       <s:selectItems value="#{fylkeList.resultList}" var="fylke" label="#{fylke.navn}"/>
       <a4j:support event="onchange" reRender="kommuneResultat" ajaxSingle="true" />
       <s:convertEntity/>
       </h:selectOneMenu>
       </s:decorate>
       <s:div id="kommuneResultat">
       <s:decorate template="/layout/display.xhtml" rendered="#{searchProeveManager.kommuner.size > 0}">
       <ui:define name="label">Kommune</ui:define>
       <h:selectOneMenu value="#{searchProeveManager.kommune}" border="0">
       <s:selectItems value="#{searchProeveManager.kommuner}" var="kom" label="#{kom.navn}"/>
       </h:selectOneMenu>
       </s:decorate>
       </s:div>
      
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Ã…r</ui:define>
       <h:inputText id="searchStringAar" value="#{searchProeveManager.searchStringAar}"/>
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space:nowrap">
       Velg året prøven ble avlagt i
       </span>
       </rich:toolTip>
       </s:decorate>
       <s:decorate template="/layout/display.xhtml">
       <ui:define name="label">Inneholder prøvetyper:</ui:define>
       <h:selectManyCheckbox value="#{searchProeveManager.proevetyper}" border="0">
       <s:selectItems value="#{proevetypeList.resultList}" var="proevetype" label="#{proevetype.beskrivelse}"/>
       <s:convertEntity/>
       </h:selectManyCheckbox>
       </s:decorate>
      
       <s:decorate template="/layout/display.xhtml">
       <h:commandButton id="findProeverSoek" value="Finn Prøver" action="#{searchProeveManager.find}" reRender="searchResults" />
       </s:decorate>
       </h:form>
      
       </rich:simpleTogglePanel>
      
       <rich:simpleTogglePanel label="Søke resultat" switchType="ajax">
       <div class="searchResults" id="proeveSokList">
       <h:outputText value="Søket resulterte i #{proeveSokList.size} treff" rendered="#{proeveSokList.size > 0}"/>
       <h:form>
       <rich:spacer height="20" rendered="#{proeveSokList.size > 0}" />
       <rich:dataTable id="proeveSokList" var="proeve" value="#{proeveSokList}" rendered="#{proeveSokList.size > 0}" rows="20" sortMode="single">
       <rich:column sortBy="#{proeve.person.etternavn}">
       <f:facet name="header"><h:outputText value="Etternavn"/></f:facet>
       <h:outputText value="#{proeve.person.etternavn}"/>
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space: nowrap">
       <strong>Navn: </strong>#{proeve.person.fornavn} #{proeve.person.mellomnavn} #{proeve.person.etternavn}<br />
       <strong>Fødselsdato: </strong>#{proeve.person.foedselsdato}<br />
       </span>
       </rich:toolTip>
       </rich:column>
       <rich:column sortBy="#{proeve.person.fornavn}">
       <f:facet name="header"><h:outputText value="Fornavn"/></f:facet>
       <h:outputText value="#{proeve.person.fornavn}"/>
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space: nowrap">
       <strong>Navn: </strong>#{proeve.person.fornavn} #{proeve.person.mellomnavn} #{proeve.person.etternavn}<br />
       <strong>Fødselsdato: </strong>#{proeve.person.foedselsdato}<br />
       </span>
       </rich:toolTip>
       </rich:column>
       <rich:column>
       <f:facet name="header"><h:outputText value="Personnummer"/></f:facet>
       <h:outputText value="#{proeve.person.personnummer}"/>
       <rich:toolTip followMouse="false" direction="top-right" styleClass="tooltip">
       <span style="white-space: nowrap">
       <strong>Navn: </strong>#{proeve.person.fornavn} #{proeve.person.mellomnavn} #{proeve.person.etternavn}<br />
       <strong>Fødselsdato: </strong>#{proeve.person.foedselsdato}<br />
       </span>
       </rich:toolTip>
       </rich:column>
       <rich:column sortBy="#{proeve.avlagt}">
       <f:facet name="header"><h:outputText value="Prøve Avlagt"/></f:facet>
       <h:outputText value="#{proeve.avlagt}"/>
       </rich:column>
       <rich:column sortBy="#{proeve.bestaatt}">
       <f:facet name="header"><h:outputText value="Prøve Bestått"/></f:facet>
       <h:outputText value="Ja" rendered="#{proeve.bestaatt}" />
       <h:outputText value="Nei" rendered="#{!proeve.bestaatt}" />
       </rich:column>
       <rich:column sortBy="#{proeve.proevetype.beskrivelse}">
       <f:facet name="header"><h:outputText value="Prøvetype"/></f:facet>
       <h:outputText value="#{proeve.proevetype.beskrivelse}"/>
       </rich:column>
       <rich:column sortBy="#{proeve.proevetypeVersjon.navn}">
       <f:facet name="header"><h:outputText value="Prøvetype versjon"/></f:facet>
       <h:outputText value="#{proeve.proevetypeVersjon.navn}"/>
       </rich:column>
       <rich:column sortBy="#{proeve.kommune.navn}">
       <f:facet name="header"><h:outputText value="Kommune"/></f:facet>
       <h:outputText value="#{proeve.kommune.navn}"/>
       <rich:toolTip showEvent="onclick" followMouse="false" mode="ajax" direction="top-right" styleClass="tooltip">
       <span style="white-space: nowrap">
       Prøven ble avlagt i <strong>#{proeve.kommune.navn}</strong> kommune
       </span>
       </rich:toolTip>
       </rich:column>
       <rich:column>
       <f:facet name="header"><h:outputText value="Rediger"/></f:facet>
       <s:link view="/protected/#{empty from ? 'Proeve' : from}.xhtml" value="Velg"
       id="proeve">
       <f:param name="proeveProeveId" value="#{proeve.proeveId}" />
       </s:link>
       </rich:column>
       </rich:dataTable>
       <rich:datascroller align="left" for="proeveSokList" maxPages="10" rendered="#{proeveSokList.size > 0}" renderIfSinglePage="false"/>
       </h:form>
       </div>
       </rich:simpleTogglePanel>
      </ui:composition>
      


        • 1. Re: a4j:support event=
          Ilya Shaikovsky Master

          what RF version you've using?

          If something changed if you'll use region instead of ajaxSingle?

          • 2. Re: a4j:support event=
            Shervin Asgari Master

            Oh, I forgot to say. I am using the latest GA version. 3.2.1 GA.

            What I basically need to clarify, is why my valuechangelistener is activated when I submit the form.

            Regards

            • 3. Re: a4j:support event=
              Shervin Asgari Master

              I tried putting <a4j:region> but still the valueChangeListener is executed and not my form action. I dont understand :(

              <a4j:region>
               <s:decorate template="/layout/display.xhtml">
               <ui:define name="label">Fylke</ui:define>
               <h:selectOneMenu valueChangeListener="#{searchProeveManager.updateKommune}" immediate="true">
               <s:selectItems value="#{fylkeList.resultList}" var="fylke" label="#{fylke.navn}" noSelectionLabel="Velg fylke"/>
               <a4j:support event="onchange" reRender="kommuneResultat"/>
               <s:convertEntity/>
               </h:selectOneMenu>
               </s:decorate>
               <s:div id="kommuneResultat">
               <s:decorate template="/layout/display.xhtml" rendered="#{searchProeveManager.kommuner.size > 0}">
               <ui:define name="label">Kommune</ui:define>
               <h:selectOneMenu value="#{searchProeveManager.kommune}" border="0">
               <s:selectItems value="#{searchProeveManager.kommuner}" var="kom" label="#{kom.navn}"/>
               </h:selectOneMenu>
               </s:decorate>
               </s:div>
              </a4j:region>


              • 4. Re: a4j:support event=
                leelavathic leelavathic Novice

                I'm having the same problem.

                But in my case the action is getting called along with the valueChangeListerner on submit of the form.

                And also the valueChangeListener is called on submit of the main form
                only on the second time or thereafter not the first time.

                I'm using richfaces 3.2.1 GA and tomcat 6.0.16

                Note: This problem is not happening in tomcat 6.0.14

                It's urgent.

                <a4j:form id="searchPanel" >
                
                <!-- other components in the main form -->
                
                 <a4j:region renderRegionOnly="true">
                 <h:panelGrid columns="3" >
                 <h:outputText value="Date range:"/>
                 <rich:spacer />
                 <h:selectOneMenu id="dateRange" valueChangeListener="#{searchBean.processDateRangeSelection}" value="#{searchBean.selDateRange}">
                 <a4j:support event="onchange" reRender="fromDate,toDate" onsubmit="setCurrentDate()"/>
                 <h:inputHidden id="currentDate" value=""/>
                 <f:selectItem itemValue=""/>
                 <f:selectItem itemValue="Next Hour"/>
                 <f:selectItem itemValue="Last Hour"/>
                 <f:selectItem itemValue="Today"/>
                 <f:selectItem itemValue="Yesterday"/>
                 <f:selectItem itemValue="Tomorrow"/>
                 <f:selectItem itemValue="Next week"/>
                 <f:selectItem itemValue="Last week"/>
                 </h:selectOneMenu>
                 <h:outputText value="From date:" />
                 <rich:spacer/>
                 <rich:calendar id="fromDate" mode="ajax" resetTimeOnDateSelect="true" maxlength="18" converterMessage="Invalid from date. Expected date in MMM dd yyyy, HH:mm" datePattern="MMM dd yyyy, HH:mm" enableManualInput="true" direction="auto" value="#{searchBean.fromDate}"/>
                 <h:outputText value="To date:" />
                 <rich:spacer/>
                 <rich:calendar id="toDate" mode="ajax" resetTimeOnDateSelect="true" maxlength="18" converterMessage="Invalid to date. Expected date in MMM dd yyyy, HH:mm" datePattern="MMM dd yyyy, HH:mm" enableManualInput="true" direction="auto" value="#{searchBean.toDate}"/>
                 </h:panelGrid>
                 </a4j:region>
                
                <!-- other components in the main form -->
                
                 <h:panelGrid columns="4">
                 <rich:spacer height="10" width="4"/>
                 <a4j:commandButton value="Search" type="submit" action="#{searchBean.doSearch}" reRender="searchPanel" limitToList="true" />
                 <rich:spacer height="10" width="5"/>
                 <a4j:commandButton value="Reset" immediate="true" type="submit" action="#{searchBean.doReset}" reRender="searchPanel" limitToList="true"/>
                 </h:panelGrid>
                </a4j:form>