Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After couple of hours of debugging I decided to improve ComponentStateHelper which is part of Mojarra JSF2 implementation. I took the last version 2.1.4 <a href="https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.1.4/javax.faces-2.1.4-sources.jar" rel="nofollow">https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.1.4/javax.faces-2.1.4-sources.jar</a></p> <p>The main idea is to preserve results of EL expressions evaluated during each phase. I am still assuming that result of EL expression must be the same within one phase.</p> <p>Changes in class javax.faces.component.ComponentStateHelper:</p> <pre><code>class ComponentStateHelper implements StateHelper , TransientStateHelper { ... // Own cache for method public Object eval(Serializable key, Object defaultValue) { int lastPhaseId = -1; // Last cached phase private Map&lt;Serializable, Object&gt; evalCache; ... public ComponentStateHelper(UIComponent component) { ... // Instantiate own cache this.evalCache = new HashMap&lt;Serializable, Object&gt;(); } ... /** * @see StateHelper#eval(java.io.Serializable, Object) */ public Object eval(Serializable key, Object defaultValue) { Object retVal = get(key); if (retVal == null) { // Value evaluated and returned within one phase should be hopefully still same int currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId().getOrdinal(); if(lastPhaseId &lt; currentPhaseId) { // Probably stale cache, so clear it to get fresh results // in current phase evalCache.clear(); lastPhaseId = currentPhaseId; } retVal = evalCache.get(key); if(retVal == null) { ValueExpression ve = component.getValueExpression(key.toString()); if (ve != null) { retVal = ve.getValue(component.getFacesContext().getELContext()); } } // Remember returned value in own cache evalCache.put(key, retVal); } return ((retVal != null) ? retVal : defaultValue); } ... } </code></pre> <p>This enhancement seems to be functional and number of calls to my managed bean decreased drastically, especially <em>rendered</em> getters which were called multiple times for the same component.</p> <p>I maybe do not see what disasterous consequences this enhancement may cause. But if this is feasable I wonder why JSF guys have not used this type of cacheing.</p> <p>*<strong>EDIT: This solution cannot be used as it has problems when combined with DataModel!!! *</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload