6 Replies Latest reply on May 16, 2007 7:47 AM by tomba

    Passing variables with ajax request

    tomba

      Hi all,

      I have an a4j:support on an onchange event for a combobox. All fine, that works as it should, except that I lose a parameter.

      When my page is first loaded, I have a http GET parameter "consulting=1". At the time that I change the selected value of my combo box, a request is sent to the server with apparently just that value. Therefore, "consulting=1" is lost and I have false results.

      Here's my code:

       <a4j:region renderRegionOnly="false">
       <h:form id="filter">
       <h:selectOneListbox onchange="submit()" id="cmbProduct" size="1" value="#{projectList.currentProduct}" style="width: 200px">
       <f:selectItems value="#{projectList.availableProducts}"/>
       <a4j:support onsubmit="Richfaces.showModalPanel('busy')" event="onchange" oncomplete="Richfaces.hideModalPanel('busy');sortables_init()" reRender="projectlist"/>
       </h:selectOneListbox>
       <h:inputHidden value="#{projectList.consulting}" />
       </h:form>
       </a4j:region>
      


      Does anyone know how to maintain this variable across different requests? As you can see I tried with an inputHidden field but that doesn't get set ater my AJAX request.

      Thank you

        • 1. Re: Passing variables with ajax request

          It hard for me to understand how it might work fine if you have onchange="submit()" that means to perform a regular non-ajax request with full page reloading.

          ...or may be submit() means something also in your code?

          • 2. Re: Passing variables with ajax request
            alexsmirnov

            You can add parameter to ajax request :

            <a4j:support onsubmit="Richfaces.showModalPanel('busy')" event="onchange" oncomplete="Richfaces.hideModalPanel('busy');sortables_init()" reRender="projectlist">
             <f:param name="consulting" value="#{params.consulting}" />
            </a4j:support>
            


            • 3. Re: Passing variables with ajax request
              tomba

              Sorry for the submit() call, it was a leftover in my code and should not have been here.

              Anyway, the a4j manual says the following:

              In this example the request contains only the input component causes the request generation, not all the components contained on a form, because of "ajaxSingle=true" usage.

              Since I have not set ajaxSingle, I would expect also hidden input fields to be sent on the ajax request.

              As for the f:param, can you also explain where I have to handle that parameter? It doesn't help putting it in the value function of the to-be-rerendered component.

              Thanks for the help

              • 4. Re: Passing variables with ajax request
                tomba

                So I tried with an f:param and even an f:attribute and with adding an actionListener in the a4j tag. However, in neither case I get the actual value but always null :(

                • 5. Re: Passing variables with ajax request
                  ilya_shaikovsky

                  Put please latest sources with f:param here. And describe the behaviour you expected for the code step by step please.

                  B.t.w. One more component to set some value to the backing bean directly, while sending an ajax request, is a4j:actionparam

                  • 6. Re: Passing variables with ajax request
                    tomba

                    Well I have solved the problem now. The problem to overcome was to still have the initial GET parameters available across different ajax requests.

                    Therefore, I made an init-param for my managed-bean and put a inputHidden field in the form.

                    Greetings,
                    Steven De Groote