3 Replies Latest reply on Apr 18, 2011 3:19 AM by lvdberg

    s:decorate: problem with correct rerendering

    rdeckbuzzamite

      The task which I have to do is the following:
      On a form where you can enter zip/city (one field) and choose country (another field), there shall be a suggestionBox for the zip/city field, but only when the country is switzerland, because for this country I have data available through a suggestion service.
      So I use a a4j:support on the country selection field where I rerender the s:decorate field containing the zip/city field.
      The effect is that the rendering condition of the suggestionbox (s:fragment) will be evaluated (correct), but the zip/city field will also be rerender, which I don't want. So I tried to rerender only the s:fragment part, but then, the condition is not evaluated correctly.
      How can I do it to not rerender the zip/city field and get the rendering condition of the suggestionBox still correct?


      Below is my code:


                <a4j:outputPanel id="locationPlzNameCountry" layout="block">
                     <s:decorate id="locationPlzName" template="/layout/forms_edits.xhtml">
                          <ui:define name="label">#{messages['myaccount.personal.codePlace']}</ui:define>
                          <ui:define name="control">
                               <h:inputText id="zipCity" value="#{personalBean.zipCity}"
                                    required="false" />
                               <s:fragment id="locationPlzNameSuggest"
                                    rendered="#{personalBean.curriculumVitae.userAccount.address.country.key == 'switzerland' || personalBean.curriculumVitae.userAccount.address.country.key == 'liechtenstein'}">
                                    <rich:suggestionbox id="zipCitySuggestionBox" height="300"
                                         width="227" var="_suggest"
                                         suggestionAction="#{locationSuggestionBean.suggestZipCity}"
                                         nothingLabel="#{messages['jobsearch.search.city.noresult']}"
                                         for="zipCity" minChars="2" limitToList="true">
                                         <h:column>
                                              <h:outputText value="#{_suggest}" />
                                         </h:column>
                                    </rich:suggestionbox>
                               </s:fragment>
                          </ui:define>
                     </s:decorate>
      
                     <s:decorate template="/layout/forms_edits.xhtml">
                          <ui:define name="label">#{messages['myaccount.personal.land']}<b
                                    class="grey">*</b>
                          </ui:define>
                          <ui:define name="control">
                               <h:selectOneMenu required="true"
                                    requiredMessage="#{messages['myaccount.curriculum.personal.country.required']}"
                                    value="#{personalBean.curriculumVitae.userAccount.address.country}">
                                    <s:selectItems value="#{myAccountBean.countryList}" var="country"
                                         label="#{countryConverter.label(country)}"
                                         noSelectionLabel="#{messages['myaccount.curriculum.no_selection']}" />
                                    <f:converter converterId="countryConverter" />
                                    <a4j:support event="onchange" reRender="locationPlzNameCountry"
                                         limitToList="true" ajaxSingle="true" />
                               </h:selectOneMenu>
                          </ui:define>
                     </s:decorate>
                </a4j:outputPanel>



      Here the forms_edit.xhtml template:


      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:s="http://jboss.com/products/seam/taglib">
          
          <div class="formEntry">
              <s:label id="inputLabel">
                  <ui:insert name="label" />
              </s:label>
              <s:span styleClass="#{invalid ? 'errors' : ''}" id="input">
                  <s:validateAll>
                           <ui:insert name="control"/>
                  </s:validateAll>
               </s:span>
               <s:span rendered="#{invalid}" styleClass="errors" id="inputError">
                     <br/>
                    <s:message styleClass="errorMessage"/>
               </s:span>                 
          </div>
          
      </ui:composition>




      Any help will be greatly appreciated!



        • 1. Re: s:decorate: problem with correct rerendering
          lvdberg

          Hi,


          You can put an additional ajax-outputpanel around the fragment which you rerender when you want to rerender that part only.


          Leo

          • 2. Re: s:decorate: problem with correct rerendering
            rdeckbuzzamite

            Hi


            Thank you for your answer.


            I just did that, with the following effect:





            • The h:inputText field doesn't get rerendered anymore (OK)




            • If I change the country, and then try to change the value in the zipCity field, then the old value gets written back somehow (even with autocomplete off!), and the suggestionbox table appears in the upper left corner with the list you had before.



            I found some information concerning a bug (https://issues.jboss.org/browse/RF-5006) where the recommendation was to always rerender the suggestionBox and the parent component, here the inputText field (that's just what I don't want to do).




            Is there a solution/workaround to this 'top left corner suggestion box' phenomena?


            Roland

            • 3. Re: s:decorate: problem with correct rerendering
              lvdberg

              Hi,


              be aware that Ajax has some tricky side effects concerning the reRender functionality. Normally everything is one big region, and averything inside it gets rerendered. Use a a4j:region to get the needed separation.


              The by you mentioned bug, mentions also a problem with concurrent reRendering, which - if this is the case for you - can be solved by using a queue in the pages (the eventsQueue-attribute) .


              Leo