Proposal: a4j:rerenderCache to cache rerenders.
luxspes Sep 11, 2009 11:51 AMWhen I do HTML/AJAX coding "by hand" (or using DWR or SeamWebRemoting) I can do something I have found to me almost impossible to do with Richfaces: AJAX Caching.
Here is an example (this also happens with chained selectOneMenus, tree expanding, tab panel switching, and many other places, but this is the most simple meaningful example I could think of:
Lets say I have a an input box, where I can write any number, and an an output text that shows its text representation, so for example if I write "1" in the outputext I see "One", if I write "2" in the inputext I see "Two".
The code would look like this:
<h:inputText value="#{numberToLetterConverter.number}" > <a4j:support event="onblur" action="#{numberToLetterConverter.convert}" reRender="text"/> </h:inputText> <h:outputText id="text" value="#{numberToLetterConverter.text}" />
Now, after I have written: 1, and 2, and 3, if I write 1 again, it will go back to the database to fetch is "letter" representantation, but it has already done that! If I were coding this with plain JS and AJAX, I could have kept some kind of "dictionary" collection that would save me the network roundtrip.
How to achieve that in Richfaces?
Well, what do you think about this (note the <a4j:rerenderCache> tag and the id of the inputText):
<h:inputText id="input" value="#{numberToLetterConverter.number}" > <a4j:support event="onblur" action="#{numberToLetterConverter.convert}" reRender="text"/> </h:inputText> <a4j:rerenderCache cacheBy="input.value"> <h:outputText id="text" value="#{numberToLetterConverter.text}" /> </a4j:rerenderCache>
the a4j:rerenderCache would keep its own dictionary of values, matching what is going to be rerendered with the las value (or comma separated values) that are specified in its cacheBy property, if the value is one that with which a re-render has already been triggered, the it will not go fecth the xhtml fragment to the database, it would just use a local javascript based cache.
What do you think? Is it doable? (I have almost zero experience building JSF controls, the way I want to build this might be flawed, but I think it is an idea with a good spirit, that could help making richfaces performance a lot better when compared with built by hand AJAX aplications)