Skip to content
Permalink
Browse files

Add Faces#getContextAttribute(supplier)

  • Loading branch information...
BalusC committed Feb 25, 2018
1 parent 58b5a5a commit c04e0eb97455fafdc276331c0d0897f1f7c0fe24
Showing with 37 additions and 1 deletion.
  1. +14 −0 src/main/java/org/omnifaces/util/Faces.java
  2. +23 −1 src/main/java/org/omnifaces/util/FacesLocal.java
@@ -495,6 +495,20 @@ public static void resolveExpressionSet(Object base, String property, Object val
return FacesLocal.getContextAttribute(getContext(), name);
}

/**
* Returns the Faces context attribute value associated with the given name, or computes the supplied value if absent.
* @param <T> The expected return type.
* @param name The Faces context attribute name.
* @param computeIfAbsent The computed Faces context attribute value when absent. Useful if it represents a collection, map or bean.
* @return The Faces context attribute value associated with the given name.
* @throws ClassCastException When <code>T</code> is of wrong type.
* @see ExternalContext#getRequestMap()
* @since 3.1
*/
public static <T> T getContextAttribute(String name, Supplier<T> computeIfAbsent) {
return FacesLocal.getRequestAttribute(getContext(), name, computeIfAbsent);
}

/**
* Sets the Faces context attribute value associated with the given name.
* @param name The Faces context attribute name.
@@ -405,8 +405,30 @@ public static ViewDeclarationLanguage getViewDeclarationLanguage(FacesContext co
* @see Faces#getRenderKit()
*/
public static RenderKit getRenderKit(FacesContext context) {
String renderKitId = null;
UIViewRoot view = context.getViewRoot();
String renderKitId = (view != null) ? view.getRenderKitId() : context.getApplication().getViewHandler().calculateRenderKitId(context);

if (view != null) {
renderKitId = view.getRenderKitId();
}

if (renderKitId == null) {
Application application = context.getApplication();
ViewHandler viewHandler = application.getViewHandler();

if (viewHandler != null) {
renderKitId = viewHandler.calculateRenderKitId(context);
}

if (renderKitId == null) {
renderKitId = application.getDefaultRenderKitId();

if (renderKitId == null) {
renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT;
}
}
}

return ((RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY)).getRenderKit(context, renderKitId);
}

0 comments on commit c04e0eb

Please sign in to comment.
You can’t perform that action at this time.