1 Reply Latest reply on Feb 25, 2010 4:49 AM by iimirela

    rich:suggestionbox

    iimirela

      Hello,

       

         I have something like this:

      <script type="text/javascript" language="javascript">

                function processObjects(elem1,  suggestionBox) {

                     var items = suggestionBox.getSelectedItems();

                     if (items[0]) {

                          document.getElementById(elem1).value = items[0].zipCode;

                     }else{

                          document.getElementById(elem1).value = '';

                      }

                  }

      </script>

      ...

      <a4j:form id="registerForm">

      ...

      <a4j:region selfRendered="true">

           <h:panelGrid columns = "4" cellpadding="0" cellspacing="0">

           <h:inputText id="zip" readonly="true" value="#{registerBean.selectedCity.zipCode}" styleClass="shortText" />

           <h:inputText id="city" styleClass="largeText" value="#{registerBean.selectedCity.name}"/>

           <h:graphicImage value="/images/buttons/btn_down.gif"

                                    onclick="#{rich:component('suggestion')}.callSuggestion(true)" />

           <rich:suggestionbox id="suggestion" for="city" fetchValue="#{result.name}" usingSuggestObjects="true"

                          onobjectchange="processObjects('registerForm:zip',#{rich:component('suggestion')})"

                          suggestionAction="#{registerBean.suggestedCities}"

                          var="result" ignoreDupResponses="true">

                     <h:column>

                               <h:outputText value="#{result.zipCode}"/>

                     </h:column>

                     <h:column>

                               <h:outputText value="#{result.name}"/>

                     </h:column>

           </rich:suggestionbox>

           </h:panelGrid>

      </a4j:region>

      ...

      </a4j:form>

       

      Works fine visually, but in the register method the selectedCity object only has name, the zip attribute is null. Which is the best way to handle this? Move the inputText 'zip' outside the a4j:region? ReRender somehow?

       

      I use richfaces 3.3.2 SR1 and the scope of the bean is request (it's a registration form).

       

      Thank you.

        • 1. Re: rich:suggestionbox
          iimirela

          Hi,

           

              I've solved my problem:

           

             1. I changed my bean's scope to 'session'.

             2. I used f:setPropertyActionListener  instead of the javascript to set the value:

           

          <a4j:region selfRendered="true">

               <h:panelGrid columns = "4" cellpadding="0" cellspacing="0">

                    <h:inputText id="zip" readonly="true" value="#{registerBean.selectedCity.zipCode}" styleClass="shortText" />

                    <h:inputText id="city" styleClass="largeText" value="#{registerBean.selectedCity.name}"/>

                    <h:graphicImage value="/images/buttons/btn_down.gif"

                              onclick="#{rich:component('suggestion')}.callSuggestion(true)" />

               </h:panelGrid>

              <rich:suggestionbox id="suggestion" for="city" fetchValue="#{result.name}"

                                             suggestionAction="#{registerBean.suggestedCities}"

                                             var="result" ignoreDupResponses="true"

                                             nothingLabel="#{pageMessages.noResultsFound}">

                         <h:column>

                              <h:outputText value="#{result.zipCode}"/>

                          </h:column>

                          <h:column>

                              <h:outputText value="#{result.name}"/>

                         </h:column>

                         <a4j:support event="onselect" ajaxSingle="true" reRender="zip">

                                   <f:setPropertyActionListener value="#{result}" target="#{registerBean.selectedCity}"/>

                        </a4j:support>

               </rich:suggestionbox>

          </a4j:region>