3 Replies Latest reply on Aug 3, 2007 9:19 AM by N D

    JSF/AJAX4JSF - restore tree - increase efficiency - ?!

    N D Newbie

      I wanted to share some of my thoughts regarding JSF and AJX4JSF, hoping to find some answers to certain questions that have popped up while developing with JSF.

      This is how I use JSF:

      - I use Spring to manage my beans because it's more flexible
      - I use faces-config.xml only to define my navigation rules
      - I use Facelets because it's great

      Now I want to add some AJAX spicing to it. I have a screen with a list of items, and below I have a tabbed detail panel. Now what I would like is this: when I select an item in the list, it displays in the detail panel. In this detail pane I can use the tabs to navigate the detail data further. But I want this to happen with AJAX. Tried with ajax4jsf - works like a charm.

      But here's my problem: whenever I click another tab, an AJAX request is sent to the server. But to handle this request, the whole component tree has to be restored. In the example above, this means every time I click a detail tab, the whole list has to be restored as well - meaning: it has to be reloaded from the database too. However, this is a huge waste of time, because it will never be used - I just want to display another part of the detail in a new tab, the list above will stay untouched.

      I tried using <a4j:region> with selfRendered="true". This works as I was hoping, meaning: it just processes the region part, except: it does not include my XHTML markup, so my tabs display as links only.

      The reason I wanted to add AJAX, was to avoid having the reload the list for every tab navigation - to speed up things. The only gain left from my intent, is that only a subpart of the page has to be sent back to the user to display. The main gain however would have been to avoid going back to the database to reload the list.

      Am I missing something or is what I am trying to do impossible with the current JSF specification or ajax4jsf version?

      Many thanks for all thoughts!

        • 1. Re: JSF/AJAX4JSF - restore tree - increase efficiency - ?!
          N D Newbie

          Is there really no one who could give me some feedback on this? Personally I think the point outlined here is quite important, because it's about wether or not AJAX and JSF can make the perfect match they promised ...


          • 2. Re: JSF/AJAX4JSF - restore tree - increase efficiency - ?!
            Igor Shabalov Apprentice

            Yes, we are well aware about this issues. You touch two problems here that are common for JSF:
            1. Tree restore on every request. This one is an obvious defect from JSF 1.0 times and it can be partially solved in 1.2, however we still maintain 1.1 compatibility. We are considering to drop support for 1.1 in future and that may open the opportunity to use better approach from 1.2, but I do not know how important 1.1 is for community.
            2. Data Table Model inefficiency. It is bad idea to load it every time from the database in any case, because on earlier phases (2-4) of the post-back you must restore exact table state as it was on phase 6 during rendering. Someone can add/delete rows in the database and this *may* create a mess on a post-back. I'd recommend use of rich:dataTable and our Extended Data Table Model, which has a features to improve efficiency of data loading.
            2.b You can avoid unnecessary re-loads if use client switch mode. However, that depends from your use case.
            2.c Yes, you cannot use xhtml markup with selfRendered, everything has to be a components. I suggest you to re-consider your markup.

            Again the question of restore view efficiency is a important for us in JSF 2.0 group and it was already discussed. We will have an ultimate solution in 2.0. Same for Data Table Model.

            • 3. Re: JSF/AJAX4JSF - restore tree - increase efficiency - ?!
              N D Newbie

              Thank you for this thorough reply. I already suspected some specification flaws were at the root of this 'evil'. But your post made it clear that it was not my misunderstanding or mistake that was hampering my solution.

              As far as I am concerned you could just drop the 1.1 support, but on the other hand it's nice to see you think about the community :).

              For the DataTable issue you discribe - that's not what I do. I simply don't use DataTable. I have taken the best of both worlds and what I liked from the old world was the passing of crucial parameters (like the ID of the item you select from a list). This eliminates the add/delete rows issue you described, and allows the managed beans from the detail page to be independent of the managed bean of the list page. As a positive side effect bookmarking pages is no longer impossible.

              Anyway, I kindly thank you for this clarification - it makes me looking forward to the JSF 2.0 release even more !!