9 Replies Latest reply on Sep 7, 2007 11:29 PM by kjohnston

    Proper use of a4j:region

    kjohnston

      I think I have figured out how a4j:region works. If I surround a section of the document with the a4j:region tag, and set renderRegionOnly="true", then any Ajax action triggered inside that region will only reRender the region - nothing outside the region will be reRendered on the server or on the client.

      The problem is - there are times that I *do* want to reRender areas outside the region. It seems that the only way I can override the region behavior is to wrap the command button / link in another region and set renderRegionOnly="false".

      Is this correct? Or is there a better way to use regions?

        • 1. Re: Proper use of a4j:region

          region is about rendering something. It might limit the potential zone, but never point on what will be re-rendered.

          • 2. Re: Proper use of a4j:region
            kjohnston

            I think I understand your response - a region doesn't specify what will be reRendered. However, am I correct in that only dynamic components inside a region will be reRendered when an Ajax call is triggered from within that region, unless renderRegionOnly is false?

            • 3. Re: Proper use of a4j:region

              reRender attribute of the Ajax Component (any of them) points to what will be re-rendered. Plus, the a4j:outputPanel might have a ajaxRendered attribute that add this outputPanel to the list of re-rendered zones.

              reRender might point to any component(s) on the page including the ones localed outside the local region. However, if renderRegionOnly is false, the update for outer zone will not be performed (will be ignored) .

              I do not understand what you mean when you say "dynamic components". We have no such term.

              • 4. Re: Proper use of a4j:region
                kjohnston

                By dynamic components - I simply meant any html tags that might be updated without updating the whole page.

                Did you mean to say that if renderRegionOnly is true, that updates for the outer zone will not be performed?

                Here is the use case I am trying to solve:

                A wizard pops up in a modal dialog window on top of a larger page. I want to only reRender the wizard pages when the user clicks next, except on the last page - when they click finish - I want to update the whole page.

                What we are seeing is that currently with each click of the 'next' button, the entire page is reRendered on the server, resulting in some expensive calls to render parts of the page that are not needed for rendering the wizard.

                Is there a way to use the region tag to achieve this? Or is this not a valid use case for the region tag?

                • 5. Re: Proper use of a4j:region

                   

                  "kjohnston" wrote:
                  By dynamic components - I simply meant any html tags that might be updated without updating the whole page.


                  So, any JSF component is a "dynamic" from the Ajax4jsf point of view


                  "kjohnston" wrote:

                  Did you mean to say that if renderRegionOnly is true, that updates for the outer zone will not be performed?


                  It sounds for me that you still do not get the point. If I says just 'yes' now, it will be true, but you will be pointed to the wrong direction.
                  So, the answer will be:
                  If you did not point to anything, it will not be performer regardless do you have region or not.

                  "kjohnston" wrote:

                  A wizard pops up in a modal dialog window on top of a larger page. I want to only reRender the wizard pages when the user clicks next, except on the last page - when they click finish - I want to update the whole page.


                  You have no reason to use a4j:region for this purpose. (It might be other purposes, but not this one)

                  "kjohnston" wrote:

                  What we are seeing is that currently with each click of the 'next' button, the entire page is reRendered on the server, resulting in some expensive calls to render parts of the page that are not needed for rendering the wizard.


                  Ajax4jsf has a a4j:include component that serves the similar purpose. See the demos and docs. Again, a4j:region does not help you here.

                  "kjohnston" wrote:

                  Is there a way to use the region tag to achieve this? Or is this not a valid use case for the region tag?

                  Not a valid use case. Reset your previous understanding.

                  • 6. Re: Proper use of a4j:region
                    kjohnston

                    Who are you? Are you a developer on this project?

                    I have spent a lot of time looking at the code and debugging with the debugger, and I *do* know what I am talking about.

                    The region tag clearly limits what is rendered on the server side. I have seen this very clearly in the debugger.

                    You won't even admit when you make a mistake in your posts? Bizarre.

                    • 7. Re: Proper use of a4j:region
                      kjohnston

                      For those interested, I have posted an example describing what I have found with the a4:region tag here:

                      http://jsfuser.blogspot.com/2007/09/using-a4jregion-tag.html

                      I welcome your comments on that blog.

                      • 8. Re: Proper use of a4j:region

                        I guess, it is a right time to speak about the JSF term "rendering". Otherwise, we will fighting to death speaking about the different things.

                        JSF has six phases in the default lifecycle. The last one of them is called "RENDER_RESPONSE". Speaking about "rendering" I mean only the process of rendering the outcome using the current renderKit on the 6th JSF lifecycle phase. None of the rest phases perform the rendering.

                        Very important artifact of the JSF in a Component Tree. JSF works with the Component Tree during the all six phases

                        The first phase names "RESTORE VIEW". The Component Tree is restored on the postback. If it is not a postback, JSF lifecycle jumps the the sixth phase directly. With Ajax4jsf, the first phase is performed the same way for Ajax or Non-Ajax request. We can manipulate with the part of the Component Tree without restoring the whole one.
                        Actually, restoring is a pretty fast operation. Getters are not invoked there (except the component binding).
                        JSF specification does not specify when and how much times the getters will be called during the lifecycle. First time some of them might be invoked starting from the second phase.

                        Second, third and fourth phases process the postback. Starting from the UPDATE_REQUEST_VALUE phase where the values from the request map are applied on the restored component tree and finishing with the UPDATE_MODEL_VALUES phase where the validated values come to the model.

                        By default, JSF start to process the tree from the very top. I.e. from the Component Tree root. Here is the key moment of the a4j:region mission. Ajax4jsf also starts the tree processing from the root, except the situation when the region is defined. If so, Ajax4jsf jumps the region base node and starts from there.

                        a4j:region defines what is going to be processed.

                        Does not matter the request map contains the value from outside components or not. As soon as the processing is started from the particular node, any "outside" data will be ignored.

                        OK. We are coming to the last, sixth phase. What is there? The regular JSF implementation starts to render the whole view starting from the root.
                        In case of AJAX RESPONSE, Ajax4jsf gathered the set of components have to be re-rendered (based on the reRendered attribute list and output panels with AjaxRendered="true" if limitToList attribute is not set to true). On the sixth phase, Ajax4jsf finds the components in the component tree one by one and render them. It finds the components starting from the Component Tree root, except the situation when renderRegionOnly at this moment is still set to true. If so, Ajax4jsf starts finding from the region base node. So, the components outside the region are not found. This is a reason why they are not rendered and not in the final AJAX RESPONSE package.


                        P.S. What about the getters. Sometimes, JSF works curiously from the end developer's point of view. Getters might be invoked several times during the lifecycle, but not during the rendering phase where this is desirable.

                        This is one more store about the case where region is useful:
                        http://jboss.com/index.html?module=bb&op=viewtopic&t=115007


                        • 9. Re: Proper use of a4j:region
                          kjohnston

                          Thank you for this response - I can see you are much more familiar with the internals of JSF and Ajax4JSF than I. Everything you are saying makes sense to me and seems consistent with what I have found, so I think we are actually in agreement.

                          So the use of a4j:region can definitely improve performance, both in what is rendered on the server and what is 'processed', including some stray getter methods that may be called during phases other than the render phase, which is exactly what I found and what I wanted to share.