miercuri, 29 aprilie 2015

[OmniFaces utilities (2.0)] Remove the resource dependency processing related attributes


[OmniFaces utilities] The removeResourceDependencyState() method remove the resource dependency processing related attributes from the given faces context.

Method:
Usage:

import org.omnifaces.util.Hacks;
...
Hacks.removeResourceDependencyState(FacesContext.getCurrentInstance());

In Mojarra, the com.sun.faces.PROCESSED_RESOURCE_DEPENDENCIES is declared in RequestStateManager#PROCESSED_RESOURCE_DEPENDENCIES, and it is used to determine of the specified @ResourceDependency has already been previously processed:

// Mojarra 2.2.9 - com.sun.faces.application.annotation.ResourceDependencyHandler
private ResourceDependency[] dependencies;
...
@SuppressWarnings({"unchecked"})
private boolean hasBeenProcessed(FacesContext ctx, ResourceDependency dep) {
 Set<ResourceDependency> dependencies = (Set<ResourceDependency>)
  RequestStateManager.get(ctx, RequestStateManager.PROCESSED_RESOURCE_DEPENDENCIES);
 return ((dependencies != null) && dependencies.contains(dep));
}

And, to indicate that the specified @ResourceDependency  has been processed:

// Mojarra 2.2.9 - com.sun.faces.application.annotation.ResourceDependencyHandler
private ResourceDependency[] dependencies;
...
@SuppressWarnings({"unchecked"})
private void markProcssed(FacesContext ctx, ResourceDependency dep) {
 Set<ResourceDependency> dependencies = (Set<ResourceDependency>)
  RequestStateManager.get(ctx, RequestStateManager.PROCESSED_RESOURCE_DEPENDENCIES);
 if (dependencies == null) {
     dependencies = new HashSet<ResourceDependency>(6);
     RequestStateManager.set(ctx, RequestStateManager.PROCESSED_RESOURCE_DEPENDENCIES, dependencies);
 }
 dependencies.add(dep);
}

Niciun comentariu:

Trimiteți un comentariu