2 Replies Latest reply on Oct 22, 2008 2:59 AM by Mehmet Salgar

    Internal Workings of the Ajax4Jsf/Richfaces

    Mehmet Salgar Novice

      Hi everybody,

      I like to ask something about the internal workings of the Ajax4Jsf/Richfaces which I think is not mentioned in the manuals....

      Lately I read a book 'JSF and Ajax Building Rich Internet Components' which is about development JSF components with Ajax functionality...

      I just to ask one detail to understand that Ajax4Jsf/Richfaces follows the same pattern or uses something different then what is described in this book.

      This books suggest using for AJAX functionality, a javascript library which is actually making a xml diff between the initial Request and Ajax request to understand anything is changed in the DOM Tree to only render this areas....

      I have a feeling Ajax4Jsf/Richfaces following another direction, instead of going all the JSF Lifecycle and all the components under the view root ,they are only concentrating to the component defined under the rerender panels....

      If this is the case, what I don't understand, lets say we have ui:repeat or a foreach which is defining a variable and this stays outside of the rerender areas. How can they handle this?

      I mean with pseudo syntax

      <ui:repeat var="testvar"

      <a4j:outputpanel id="testpanel1" layout="none" />
      <h:outputText value="#{testvar.xxx}" />
      </a4j:outputpanel>

      <a4j:poll id="testpool" rerender="testpoll,testpanel1" />

      would never work correctly if all the JSF components are not processed?

      Can anybody tell me the internals of the Ajax4Jsf/Richfaces?

        • 1. Re: Internal Workings of the Ajax4Jsf/Richfaces
          Nick Belaevski Master

          Hi,

          There's a special a4j:repeat component developed for correct processing of ajax requests. All AJAX iteration components have ajaxKeys attributes that allows to define a Set of row keys (keys are numbers for sequence components like repeat or dataTable) for which re-rendering will be done.

          Compare:

          <a4j:repeat ajaxKeys="#{forum5Bean.keys}" value="#{forum5Bean.data}">
           <h:panelGroup id="group" layout="block" style="color: black">
           <h:outputText value="#{forum5Bean.time}" />
           </h:panelGroup>
           </a4j:repeat>
          
           <h:form>
           <a4j:poll reRender="group" interval="2000"></a4j:poll>
           </h:form>


          1. Define rows to be re-rendered:
          public class Forum5Bean {...
           public Set getKeys() {
           HashSet set = new HashSet();
           set.add(3);
           set.add(5);
          
           return set;
           }
          
          ...
          }


          or 2. re-render all of them:

          public class Forum5Bean {...
           public Set getKeys() {
           return null;
           }
          
          ...
          }


          See: org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(FacesContext, UIComponent, String, Set, Set), org.ajax4jsf.component.AjaxViewRoot and org.ajax4jsf.component.UIDataAdaptor.encodeAjaxChild(FacesContext, String, Set, Set) for more implementation details.

          I have a feeling Ajax4Jsf/Richfaces following another direction, instead of going all the JSF Lifecycle and all the components under the view root ,they are only concentrating to the component defined under the rerender panels....
          In fact, all components are processed on 1-5 phase except for the case when a4j:region component or ajaxSingle/process attributes are used. On the 6th phase the whole component tree is searched for components to re-render too.

          • 2. Re: Internal Workings of the Ajax4Jsf/Richfaces
            Mehmet Salgar Novice

             

            In fact, all components are processed on 1-5 phase except for the case when a4j:region component or ajaxSingle/process attributes are used. On the 6th phase the whole component tree is searched for components to re-render too.


            So I am right about my guess that Ajax4Jsf/Richfaces search explicitly in Phase 6 (Render I assume) the components tag to be rerendered only...and only process them.....

            Thx for the answer and tips...