5 Replies Latest reply on Jun 11, 2008 10:07 AM by Luca Borzani

    ajaxOnly breaks ajax?!?

    Luca Borzani Newbie

      I have an a4j:keepAlive with ajaxOnly set to true. In the same page there's an h:commandLink. If i keep the ajaxOnly attribute set to true the commandLink won't trigger the action method but if i remove it the commandLink will work.
      In another page i have some components for which i set the binding attribute. This components won't behave correctly if i don't set ajaxOnly (for the keepAlive) to true. Since this is a little confusing to me, i would like to take a better insight of the ajaxOnly attribute.

      How is it supposed to work? Why it is breaking action-method calls if i set it to true? And why components with binding attribute set won't behave as expected if i don't set ajaxOnly to true? Is that a problem of ajaxOnly or keepAlive?

      regards :)

        • 1. Re: ajaxOnly breaks ajax?!?
          Ilya Shaikovsky Master

          1) ajaxOnly just disables request scoped bean saving if not ajax request processed.
          2) Your bean in this case just recreated when you hit h:command*. So there is nothing about ajax..

          • 2. Re: ajaxOnly breaks ajax?!?
            Luca Borzani Newbie

            I think you concentrated too much on the 'ajax' word and not on what i asked. why if i use ajaxOnly the page breaks? action-methods are no more called (at all) and binding attribute behave not as expected. How do i solve this?

            • 3. Re: ajaxOnly breaks ajax?!?
              Ilya Shaikovsky Master

              :) Seems you misunderstand me.. I do not think that I concentrated on ajax world, because my main points was that your beans is request scoped for normal requests and "session" scoped for ajax ones on the page. So the reason of "strange" behaviour just in JSF world ;)

              paste some example please with your comments to make concrete questions clear.

              • 4. Re: ajaxOnly breaks ajax?!?
                Ilya Shaikovsky Master

                Put phaseTracker to your web-inf/lib in order to check server log of Lifecycle phases execution for requests where action doesn't called.

                • 5. Re: some examples
                  Luca Borzani Newbie

                  :)
                  Here are the first example:
                  In this case i use binding on the components of the form. What i want to achieve in pseudo code is:

                   while "user has not made a selection":
                   "keep all fields disabled" (via binding properties)
                   then:
                   "take user selection"
                   "enable all fields" (via binding properties) # the problem is here
                   "fill some of the fields with data based on user selection"
                  


                  so, i have a structure like this (rts namespace are facelets compositions)

                  # keep alive and ajax only
                  <a4j:keepAlive beanName="opportunity" ajaxOnly="true"/>
                   # a simple form (a table on top of a tab set)
                   <a4j:outputPanel id="opp-panel" layout="block">
                   <rich:panel header="Nuova Opportunità ">
                   <h:panelGrid columns="4" styleClass="myTable" columnClasses="labelColumn,inputColumn">
                   <h:outputLabel value="#{oppLabel.bpCode}" />
                   <h:panelGroup>
                   <h:inputText styleClass="binocols" disabled="true" value="#{opportunity.opportunityBean.selectedBpCode}" id="hdn_bp_id" />
                   <rts:popupTrigger id="id_bp-trigger" for="id_bp_popup" reset="true" img="/resources/images/16x16/edit-find1.png"
                   bean="${searchBean}" action="reinit">
                   <f:attribute name="search_action" value="100" />
                   </rts:popupTrigger>
                   </h:panelGroup>
                  
                   <h:outputLabel value="#{oppLabel.oppDescr}" />
                   <h:inputText id="opp_descr" styleClass="formField" binding="#{opportunity.descriptionInput}" value="#{opportunity.opportunityBean.sapOpportunityDescription}" />
                  
                   <h:outputLabel value="#{oppLabel.contact}" />
                   <h:selectOneMenu id="opp_cnt" styleClass="formField" binding="#{opportunity.contactSelect}" value="#{opportunity.opportunityBean.sapContact}" >
                   <f:selectItems value="#{opportunity.contacts}" />
                   </h:selectOneMenu>
                  
                   // more fields and labels
                   </h:panelGrid>
                   </rich:panel>
                   </a4j:outputPanel> <!-- bp panel -->
                  
                   <a4j:outputPanel id="tab_set" layout="block">
                   <rich:tabPanel id="tab-panel" switchType="client" >
                   <rich:tab label="#{tab.potTab}" id="pot_tab" binding="#{opportunity.potentialTab}">
                   <h:panelGrid styleClass="myTable" columnClasses="labelColumn,inputColumn" columns="2">
                   <h:outputLabel value="#{oppLabel.plannedCls}" />
                   <rich:calendar id="opp_planned_cls" locale="#{view.locale}" popup="true" binding="#{opportunity.closeDateCalendar}"
                   datePattern="dd/MM/y" enableManualInput="false" value="#{opportunity.opportunityBean.sapPlannedClosure}" />
                  
                  
                   <h:outputLabel value="#{oppLabel.potImp}" />
                   <h:inputText id="opp_pot_imp" styleClass="formField" binding="#{opportunity.potentialImportInput}" value="#{opportunity.opportunityBean.sapPotentialImport}" />
                  
                   // more fields and labels
                  
                  
                   </h:panelGrid>
                   </rich:tab>
                   // other tabs and final buttons for submit and reset are not shown
                  


                  the action we are interested in (the one will enable all fields) is the following:
                  <a4j:commandButton type="submit" oncomplete="Richfaces.hideModalPanel('${id}');" reRender="${reRender}" id="${id}-submit-btn" actionListener="#{bean[method]}" />
                  

                  in this first example the action-method will be called, all the properties will be switched from disabled=true to disabled=false but after reRender all fields will be still disabled (although in the bean are 'enabled')
                  here is the first thing i don't undestand: if i use ajaxonly=true fields after reRender will be enabled (what i don't undestand is why ajaxonly makes the magic, why have i to use it in this case to make all things work?)

                  having sayd this, i placed ajaxOnly=true on another page. This page has code very similar to the snippet posted above (just another form with tabs and buttons). On this page, using ajaxOnly will break all action-methods (these are called the same way as on the other page).
                  So, with these two scenarios, what i don't undestand is why on a page ajaxOnly is a magic attribute (in my case 'helps' reRender-ing) and on another cause troubles.

                  The phaseTracker you are talking about is the one from jsf-comp? If yes, i can't use it with facelets because it bother me with issues about malformed xml. If it's a more gentle tracker you are talking about, please point me to the resource link.

                  thanks