My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...









[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Petition by Java EE Guardians


luni, 20 aprilie 2015

[OmniFaces utilities (2.0)] Get the render IDs from the RichFaces PartialViewContext implementation (until RichFaces 4.5)

[OmniFaces utilities] The getRichFacesRenderIds() method returns the render IDs from the RichFaces PartialViewContext implementation. RichFaces PartialViewContext implementation does not have the getRenderIds() method properly implemented. So a hack wherin the exact name of the private field needs to be known has to be used to properly extract it from the RichFaces PartialViewContext implementation.


If you read the documentation for PartialViewContext#getRenderIds() and you didn't understand exactly what it does, then here it is a quick overview. When we submit a form via an AJAX request (managed by JSF via PartialViewContext), the value of the render attribute it one of the reserved values (e.g. @form) and/or a list of clientIds separated by space. Practically, the value of the render attribute is available in the request parameters map under the javax.faces.partial.render parameter (or, PartialViewContext#PARTIAL_RENDER_PARAM_NAME), as in figure below:

<h:form id="loginFormId">             
 E-mail: <h:inputText id="emailId" value="#{}"/>               
 Info: <h:inputSecret id="passwordId" value="#{loginBean.password}"/>                                         
 <h:commandButton id="submitId" value="Login" action="#{loginBean.loginAction()}">       
  <f:ajax execute="@form" render="emailId passwordId"/>
The loginFormId:emailId and loginFormId:passwordId are returned by the PartialViewContext#getRenderIds() in a Collection of Strings (see Ajax#getContext()):  

import org.omnifaces.util.Ajax;
import java.util.Collection;
PartialViewContext pvContext= Ajax.getContext();
// e.g. [loginFormId:emailId, loginFormId:passwordId]
Collection<String> renderIds = pvContext.getExecuteIds();

If you are curious to see how this method is implemented, then check below the Mojarra 2.2.9 implementation (the relevant code was highlighted):

// Mojarra 2.2.9 - PartialViewContextImpl
public Collection<String> getRenderIds() {
  if (renderIds != null) {
      return renderIds;
  renderIds = populatePhaseClientIds(PARTIAL_RENDER_PARAM_NAME);
  return renderIds;

private List<String> populatePhaseClientIds(String parameterName) {

 Map<String,String> requestParamMap =
 String param = requestParamMap.get(parameterName);
 if (param == null) {
     return new ArrayList<String>();
 } else {
     Map<String, Object> appMap =
     String[] pcs = Util.split(appMap, param, "[ \t]+");
     return ((pcs != null && pcs.length != 0)
              ? new ArrayList<String>(Arrays.asList(pcs))
              : new ArrayList<String>());

Now, in RichFaces (until version 4.5) this method is not properly implemented. So, OmniFaces comes with Hacks#getRichFacesRenderIds() which fixes the problems. This method can be invoked as below:

import org.omnifaces.util.Hacks;
import java.util.Collection;
Collection<String> renderIds = Hacks.getRichFacesRenderIds();

Niciun comentariu :

Trimiteți un comentariu


Postări populare

OmniFaces/JSF Fans

Visitors Starting 4 September 2015

Locations of Site Visitors