9 Replies Latest reply on Mar 5, 2010 9:16 AM by maran001.nilay

    How to make ajax call from inside of a4j:support?

      <h:selectOneRadio id="yes_no" value="#{generalInfoService.answer}" immediate="true" valueChangeListener="#{generalInfoService.answerClicked}">
                  <f:selectItem id="app1" styleClass="label" itemLabel="Yes" itemValue="Yes" />
                  <f:selectItem id="app2" styleClass="label" itemLabel="No" itemValue="No" />
                  <a4j:support event="onclick"  reRender="formsection, nextprevious" requestDelay="200" eventsQueue="settingsQueue"                similarityGroupingId="settings" limitToList="true"/>              

      </h:selectOneRadio>

      <a4j:outputPanel layout="block" id="formsection">
               <h:panelGroup rendered="#{generalInfoService.dataExists}">
              <div align="right">
                  <h:commandButton type="submit" value="Save" action="#{generalInfoService.saveCancel}"/>
                  <rich:spacer width="4" height="0" />
                  <h:commandButton  value="Cancel"  immediate="true" action="#{generalInfoService.saveCancel}"/>
                  <a4j:support event="onclick" reRender="formsection1" requestDelay="200" eventsQueue="settingsQueue" ajaxSingle="true"                similarityGroupingId="settings" />    

              </div>          
              </h:panelGroup>
      </a4j:outputPanel>

      <a4j:outputPanel layout="block" id="formsection1">
              <h:panelGroup rendered="#{generalInfoService.showhide}">
                      Form Section 1
              <h:panelGroup>
         
      </a4j:outputPanel>

       

      In the above code i am facing a problen that when i am trying to make second ajax call (generalInfoService.saveCancel), it not calling the corrosponding method.

       

      what i have done wrong here? Please, need help asap...

       

      Thanks

        • 1. Re: How to make ajax call from inside of a4j:support?
          ilya_shaikovsky
          do not nest support to h:command's to send ajax requests. It will cause two concurent requests to be sent. Use just a4j:command.
          • 2. Re: How to make ajax call from inside of a4j:support?

            I tried with replacing h:commandButton to a4j:commandButton, but the problem is, it is not calling the desired method.

            Please guide me with an example to achieve that.

            • 3. Re: How to make ajax call from inside of a4j:support?

              Here just an example which is not working:

               

              <h:form id="myform">
                   <a4j:queue/>
                   <h:panelGrid columns="2">
                        <h:selectOneRadio id="yes_no" value="#{generalInfoService.answer}" immediate="true" valueChangeListener="#{generalInfoService.answerClicked}">
                          <f:selectItem id="app1" styleClass="label" itemLabel="Yes" itemValue="Yes" />
                          <f:selectItem id="app2" styleClass="label" itemLabel="No" itemValue="No" />
                         <a4j:support event="onclick" reRender="savecancel" action="#{generalInfoService.save}" requestDelay="100"/>
                    </h:selectOneRadio>
                     </h:panelGrid>
              </h:form>
              <a4j:outputPanel id="savecancel">
                  <a4j:commandButton  type="submit" value="SAVE" action="#{generalInfoService.save}"/>
                  <rich:spacer width="4" height="0" />
                  <a4j:commandButton  type="submit" value="CANCEL" action="#{generalInfoService.cancel}"/>
              </<a4j:outputPanel>

               

              while clicking on save/ cancel the desired function is not fired. Don't know what's the problem...

              • 4. Re: How to make ajax call from inside of a4j:support?
                Move the a4j output panel within h:form and see if it works.
                • 5. Re: How to make ajax call from inside of a4j:support?

                  I tried but still now luck...

                  need more help...

                  • 6. Re: How to make ajax call from inside of a4j:support?

                    I have something like this.. and it works..

                     

                    <a4j:commandButton action="#{ReminderController.filter}"

                    value="#{reminder.filter}" reRender="pickassociates"></a4j:commandButton>

                     

                    BTW, what is the type="submit" in the tag that you have used? I dont see in documentation.. am I looking at wrong place?

                    • 7. Re: How to make ajax call from inside of a4j:support?

                      <h:form>  
                              <a4j:outputPanel id="op_tipoConsulta">  
                                  <h:selectOneRadio value="#{generalInfoService.answer}"  valueChangeListener="#{generalInfoService.answerClicked}">  
                                      <f:selectItem itemLabel="Caixa" itemValue="Yes"/>  
                                      <f:selectItem itemLabel="Formulario" itemValue="No"/>  
                                      <a4j:support event="onclick" reRender="op_tipoFormulario" />  
                                  </h:selectOneRadio>  
                              </a4j:outputPanel>  
                              <a4j:outputPanel id="op_tipoFormulario">  
                                  <s:fragment rendered="#{not empty generalInfoService.answer and generalInfoService.answer != 'No'}">  
                                      <h:selectManyCheckbox value="#{generalInfoService.answer1}" valueChangeListener="#{generalInfoService.saveCancel}">  
                                          <f:selectItem itemLabel="Test 1" itemValue="Yes"/>  
                                          <f:selectItem itemLabel="Test 2" itemValue="No"/>  
                                          <a4j:support event="onclick" reRender="op_tipoConsultaCaixa"/>  
                                      </h:selectManyCheckbox>  
                                  </s:fragment>  
                              </a4j:outputPanel>  
                              <a4j:outputPanel id="op_tipoConsultaCaixa">  
                                  <s:fragment rendered="#{generalInfoService.answer != 'No'}">  
                                      Yahhooo  
                                  </s:fragment>  
                              </a4j:outputPanel>  
                          </h:form>

                       

                      Please look at the code above:

                      1. For first call to generalInfoService.answerClicked, it works properly

                      2. For second call to generalInfoService.saveCancel, it doesn't work

                       

                      Let me know if i ma doing something wrong here...

                      • 8. Re: How to make ajax call from inside of a4j:support?
                        ilya_shaikovsky

                        1) command controls has to be encosed with form.

                        2) add rich:messages to the page.

                        • 9. Re: How to make ajax call from inside of a4j:support?

                          Please look at this sample and try to understand my problem.

                          I think i am not able to communicate my problem properly..

                           

                          <h:form>  
                                  <a4j:outputPanel id="op_tipoConsulta">  
                                      <h:selectOneRadio value="#{generalInfoService.answer}"  valueChangeListener="#{generalInfoService.answerClicked}">  
                                          <f:selectItem itemLabel="Caixa" itemValue="Yes"/>  
                                          <f:selectItem itemLabel="Formulario" itemValue="No"/>  
                                          <a4j:support event="onclick" reRender="op_tipoFormulario" />  
                                      </h:selectOneRadio>  
                                  </a4j:outputPanel>  
                                  <a4j:outputPanel id="op_tipoFormulario">  
                                      <s:fragment rendered="#{not empty generalInfoService.answer and generalInfoService.answer != 'No'}">  
                                          <h:selectManyCheckbox value="#{generalInfoService.answer1}" valueChangeListener="#{generalInfoService.saveCancel}">  
                                              <f:selectItem itemLabel="Test 1" itemValue="Yes"/>  
                                              <f:selectItem itemLabel="Test 2" itemValue="No"/>  
                                              <a4j:support event="onclick" reRender="op_tipoConsultaCaixa"/>  
                                          </h:selectManyCheckbox>  
                                      </s:fragment>  
                                  </a4j:outputPanel>  
                                  <a4j:outputPanel id="op_tipoConsultaCaixa">  
                                      <s:fragment rendered="#{generalInfoService.answer != 'No'}">  
                                          Yahhooo  
                                      </s:fragment>  
                                  </a4j:outputPanel>  
                              </h:form>

                           

                          Please look at the code above:

                          1. For first call to generalInfoService.answerClicked, it works properly

                          2. For second call to generalInfoService.saveCancel, it doesn't work

                           

                          Let me know if i am doing something wrong here...