5 Replies Latest reply on Dec 4, 2008 10:10 AM by scottstevenson

    Multiple <a4j:status> within a <a4j:region>

    scottstevenson

      MyFaces 1.1.5
      RichFaces 3.1.6

      I have a page which uses an <a4j:repeat> to render a dynamic number of "portlets" (they are not real portlets, only some static HTML pulled from other applications) when the page is loaded. It is not possible to use a <a4j:region> within <a4j:repeat> (see http://www.jboss.org/jbossajax4jsf/docs/devguide/en/html/BasicConceptsOfTheAjax4jsfFramework.html#SomeProblemsWithRendering ) so everything must go inside the same region.

      I have a requirement to show a loading indicator for each section however, as I only have one region I only get one indicator.

      Any idea how I would go about creating an indicator for each area that I am loading? My code is below. Thanks in advance.



      <f:verbatim>
       <script type="text/javascript" />
       var rowCount = 0;
       var loadPortalJS = "";
       </script>
      </f:verbatim>
      
      <a4j:log />
      <t:htmlTag value="BR" />
      <a4j:region>
       <a4j:repeat value="#{portalBean.portalList}" var="portal" rowKeyVar="row"
       ajaxKeys="#{portalBean.rowKeys}">
       <a4j:portlet>
       <a4j:jsFunction name="loadPortal#{row}" action="#{portalBean.actionLoadPortal}"
       reRender="portalData">
       <a4j:actionparam name="row" value="#{row}" />
       </a4j:jsFunction>
       <jsfsdc:section value="#{portal.title}">
       <jsfsdc:column>
       <a4j:status>
       <f:facet name="start">
       <jsfsdc:outputText value="Loading..." />
       </f:facet>
       <f:facet name="stop">
       <jsfsdc:outputText value=" " escape="false" />
       </f:facet>
       </a4j:status>
      
       </jsfsdc:column>
       <jsfsdc:column>
       <t:panelGroup id="portalData">
       <t:outputText value="#{portal.portalData}" escape="false" />
       </t:panelGroup>
       </jsfsdc:column>
       <jsfsdc:column>
       <t:div />
       </jsfsdc:column>
       <jsfsdc:column>
       <jsfsdc:selectOne value="#{portal.dropDownValue}" defaultValue="false">
       <f:selectItem itemLabel="5" itemValue="5" />
       <f:selectItem itemLabel="15" itemValue="15" />
       <f:selectItem itemLabel="25" itemValue="25" />
       <a4j:support event="onchange" action="#{portalBean.actionLoadPortal}" reRender="portalData" >
       <a4j:actionparam name="row" value="#{row}" />
       </a4j:support>
       </jsfsdc:selectOne>
       </jsfsdc:column>
       <jsfsdc:column>
       <t:div />
       </jsfsdc:column>
       <jsfsdc:column>
       <a4j:commandButton value="Refresh" action="#{portalBean.actionLoadPortal}"
       reRender="portalData">
       <a4j:actionparam name="row" value="#{row}" />
       </a4j:commandButton>
       </jsfsdc:column>
       </jsfsdc:section>
       <t:htmlTag value="BR" />
       <t:htmlTag value="BR" />
       <f:verbatim>
       <script type="text/javascript" />
       loadPortalJS = loadPortalJS+'loadPortal' + rowCount++ +'();';
       </script>
       </f:verbatim>
       </a4j:portlet>
       </a4j:repeat>
      </a4j:region>
      <rich:jQuery selector="document" timing="onload" query="each(function () {eval(loadPortalJS);});"/>


        • 1. Re: Multiple <a4j:status> within a <a4j:region>
          nbelaevski

          Hello,

          Try to add a4j:status inside a4j:repeat and point a4j:jsFunction to it using status attribute.

          • 2. Re: Multiple <a4j:status> within a <a4j:region>
            scottstevenson

            Hi nbelaevski,

            I already tried something like this:

            <a4j:region>
             <a4j:repeat value="#{portalBean.portalList}" var="portal" rowKeyVar="row"
             ajaxKeys="#{portalBean.rowKeys}">
             <a4j:portlet>
            
             <jsfsdc:section value="#{portal.title}">
             <jsfsdc:column>
             <a4j:status id="ajaxStatus">
             <f:facet name="start">
             <jsfsdc:outputText value="Loading..." />
             </f:facet>
             <f:facet name="stop">
             <jsfsdc:outputText value=" " escape="false" />
             </f:facet>
             </a4j:status>
             <a4j:jsFunction name="loadPortal#{row}" action="#{portalBean.actionLoadPortal}"
             reRender="portalData" status="ajaxStatus">
             <a4j:actionparam name="row" value="#{row}" />
             </a4j:jsFunction>
            .
            .
            .


            However it always displays the first rendered <a4j:status> on the request. When I look at the rendered HTML it renders the <a4j:status> code multiple times but with the same, fixed id. It can't differentiate between the multiple occurences and chooses the first one it seems.

            It could be a problem with my version of RichFaces (3.1.6) but it's not possible for me to upgrade at the moment.

            Any other suggestions / workarounds?








            • 3. Re: Multiple <a4j:status> within a <a4j:region>
              ilya_shaikovsky

              b.t.w. Region component inside a4j repeat and all the iteration components from RF already could be used. (Starting from 3.2.0). Just check actual docs - there should not be such limitation.


              Hello,

              Try to add a4j:status inside a4j:repeat and point a4j:jsFunction to it using status attribute.


              It seems for me that Nick slightly mistaken and wanted to write outside region.

              • 4. Re: Multiple <a4j:status> within a <a4j:region>
                ilya_shaikovsky

                and me mistaken to. should be "outside repeat"

                • 5. Re: Multiple <a4j:status> within a <a4j:region>
                  scottstevenson

                  Thanks for the help guys. I eventually got it working using some nasty JavaScript and handling the status manually.

                  It's not pretty but it works. I'll refactor when we upgrade to 3.2.x.