Class ComponentUtils

java.lang.Object
org.primefaces.util.ComponentUtils

public class ComponentUtils extends Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final Lazy<Set<javax.faces.component.visit.VisitHint>>
     
    static final Set<javax.faces.component.visit.VisitHint>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    calculateViewId(javax.faces.context.FacesContext context)
    Calculates the current viewId - we can't get it from the ViewRoot if it's not available.
    static <T> T
    computeIfAbsent(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)
    Tries to retrieve value from stateHelper by key first.
    static String
    Creates an RFC 6266 Content-Dispostion header following all UTF-8 conventions.
    static void
    decodeBehaviors(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
     
    static String
    encodeComponent(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
    Encodes the given component locally as HTML.
    static void
    encodeIndexedId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, int index)
    GitHub #7763 Renders an in memory UIComponent and updates its ID with an index.
    static String
    encodeURI(String string)
    Duplicate code from OmniFacew project under apache license: https://github.com/omnifaces/omnifaces/blob/develop/license.txt
    static String
     
    static <T> T
    eval(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)
    Tries to retrieve value from stateHelper by key first.
    static <T> T
    executeInRequestScope(javax.faces.context.FacesContext context, String var, Object value, Supplier<T> callback)
     
    static javax.faces.application.NavigationCase
    findNavigationCase(javax.faces.context.FacesContext context, String outcome)
     
    static String
    getConvertedAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
     
    static String
    getConvertedAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object converter, Object value)
     
    static Object
    getConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
     
    static Object
    getConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object converter, Object value)
     
    static javax.faces.convert.Converter
    getConverter(javax.faces.context.FacesContext context, Class<?> forClass)
     
    static javax.faces.convert.Converter
    getConverter(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
    Finds appropriate converter for a given value holder
    static Object
    getDynamicColumnValue(javax.faces.component.UIComponent component)
     
    static String
    getDynamicColumnValueAsString(javax.faces.component.UIComponent component)
     
    static Object
    getLabel(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
     
    static int
    getRenderedChildCount(javax.faces.component.UIComponent component)
     
    getUIParams(javax.faces.component.UIComponent component)
     
    static <T extends javax.faces.render.Renderer>
    T
    getUnwrappedRenderer(javax.faces.context.FacesContext context, String family, String rendererType)
     
    static String
    getValueToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
     
    static String
    getValueToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
    Algorithm works as follows; - If it's an input component, submitted value is checked first since it'd be the value to be used in case validation errors terminates jsf lifecycle - Finally the value of the component is retrieved from backing bean and if there's a converter, converted value is returned
    static boolean
    isDisabledOrReadonly(javax.faces.component.UIInput component)
     
    static boolean
    isFlex(javax.faces.context.FacesContext context, FlexAware component)
     
    static boolean
    isNestedWithinIterator(javax.faces.component.UIComponent component)
    Hack for Mojarra as our UIData is copied from Mojarra.
    static boolean
    isRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
     
    static boolean
    isRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context, String event)
     
    static boolean
    isRTL(javax.faces.context.FacesContext context, RTLAware component)
     
    static boolean
    isSkipIteration(javax.faces.component.visit.VisitContext visitContext, javax.faces.context.FacesContext context)
     
    static boolean
    isTouchable(javax.faces.context.FacesContext context, TouchAware component)
     
    static boolean
    isUIRepeat(javax.faces.component.UIComponent component)
     
    isViewPooling(javax.faces.context.FacesContext context)
     
    static void
    processDecodesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
     
    static void
    processUpdatesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
     
    static void
    processValidatorsOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
     
    static boolean
    shouldRenderChildren(javax.faces.component.UIComponent component)
    Checks if the component's children are rendered
    static boolean
    shouldRenderFacet(javax.faces.component.UIComponent facet)
    Checks if the facet and one of the first level children is rendered.
    static boolean
    shouldRenderFacet(javax.faces.component.UIComponent facet, boolean alwaysRender)
    Checks if the facet and one of the first level children is rendered.
    static javax.faces.convert.Converter
    toConverter(javax.faces.context.FacesContext context, Object object)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VISIT_HINTS_SKIP_UNRENDERED

      public static final Set<javax.faces.component.visit.VisitHint> VISIT_HINTS_SKIP_UNRENDERED
    • VISIT_HINTS_SKIP_ITERATION

      public static final Lazy<Set<javax.faces.component.visit.VisitHint>> VISIT_HINTS_SKIP_ITERATION
    • SKIP_ITERATION_HINT

      public static final String SKIP_ITERATION_HINT
      See Also:
  • Method Details

    • getValueToRender

      public static String getValueToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
    • getValueToRender

      public static String getValueToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
      Algorithm works as follows; - If it's an input component, submitted value is checked first since it'd be the value to be used in case validation errors terminates jsf lifecycle - Finally the value of the component is retrieved from backing bean and if there's a converter, converted value is returned
      Parameters:
      context - FacesContext instance
      component - UIComponent instance whose value will be returned
      value - The value of UIComponent if already evaluated outside. E.g. in the renderer.
      Returns:
      End text
    • getConverter

      public static javax.faces.convert.Converter getConverter(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
      Finds appropriate converter for a given value holder
      Parameters:
      context - FacesContext instance
      component - ValueHolder instance to look up converter for
      Returns:
      Converter
    • getConvertedValue

      public static Object getConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
    • getConvertedValue

      public static Object getConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object converter, Object value)
    • getConvertedAsString

      public static String getConvertedAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)
    • getConvertedAsString

      public static String getConvertedAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object converter, Object value)
    • getConverter

      public static javax.faces.convert.Converter getConverter(javax.faces.context.FacesContext context, Class<?> forClass)
    • toConverter

      public static javax.faces.convert.Converter toConverter(javax.faces.context.FacesContext context, Object object)
    • decodeBehaviors

      public static void decodeBehaviors(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
    • escapeSelector

      public static String escapeSelector(String selector)
    • isRTL

      public static boolean isRTL(javax.faces.context.FacesContext context, RTLAware component)
    • isTouchable

      public static boolean isTouchable(javax.faces.context.FacesContext context, TouchAware component)
    • isFlex

      public static boolean isFlex(javax.faces.context.FacesContext context, FlexAware component)
    • processDecodesOfFacetsAndChilds

      public static void processDecodesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
    • processValidatorsOfFacetsAndChilds

      public static void processValidatorsOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
    • processUpdatesOfFacetsAndChilds

      public static void processUpdatesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
    • findNavigationCase

      public static javax.faces.application.NavigationCase findNavigationCase(javax.faces.context.FacesContext context, String outcome)
    • getUIParams

      public static Map<String,List<String>> getUIParams(javax.faces.component.UIComponent component)
    • isSkipIteration

      public static boolean isSkipIteration(javax.faces.component.visit.VisitContext visitContext, javax.faces.context.FacesContext context)
    • getUnwrappedRenderer

      public static <T extends javax.faces.render.Renderer> T getUnwrappedRenderer(javax.faces.context.FacesContext context, String family, String rendererType)
    • calculateViewId

      public static String calculateViewId(javax.faces.context.FacesContext context)
      Calculates the current viewId - we can't get it from the ViewRoot if it's not available.
      Parameters:
      context - The FacesContext.
      Returns:
      The current viewId.
    • encodeURI

      public static String encodeURI(String string) throws UnsupportedEncodingException
      Duplicate code from OmniFacew project under apache license: https://github.com/omnifaces/omnifaces/blob/develop/license.txt

      URI-encode the given string using UTF-8. URIs (paths and filenames) have different encoding rules as compared to URL query string parameters. URLEncoder is actually only for www (HTML) form based query string parameter values (as used when a webbrowser submits a HTML form). URI encoding has a lot in common with URL encoding, but the space has to be %20 and some chars doesn't necessarily need to be encoded.

      Parameters:
      string - The string to be URI-encoded using UTF-8.
      Returns:
      The given string, URI-encoded using UTF-8, or null if null was given.
      Throws:
      UnsupportedEncodingException - if UTF-8 is not supported
    • createContentDisposition

      public static String createContentDisposition(String value, String filename)
      Creates an RFC 6266 Content-Dispostion header following all UTF-8 conventions.

      Parameters:
      value - e.g. "attachment"
      filename - the name of the file
      Returns:
      a valid Content-Disposition header in UTF-8 format
    • isRequestSource

      public static boolean isRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
    • isRequestSource

      public static boolean isRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context, String event)
    • getLabel

      public static Object getLabel(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)
    • shouldRenderFacet

      public static boolean shouldRenderFacet(javax.faces.component.UIComponent facet, boolean alwaysRender)
      Checks if the facet and one of the first level children is rendered.
      Parameters:
      facet - The Facet component to check
      alwaysRender - flag to ignore children and only check the facet itself
      Returns:
      true if the facet should be rendered, false if not
    • shouldRenderFacet

      public static boolean shouldRenderFacet(javax.faces.component.UIComponent facet)
      Checks if the facet and one of the first level children is rendered.
      Parameters:
      facet - The Facet component to check
      Returns:
      true when facet and one of the first level children is rendered.
    • shouldRenderChildren

      public static boolean shouldRenderChildren(javax.faces.component.UIComponent component)
      Checks if the component's children are rendered
      Parameters:
      component - The component to check
      Returns:
      true if one of the first level child's is rendered.
    • eval

      public static <T> T eval(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)
      Tries to retrieve value from stateHelper by key first. If the value is not present (or is null), then it is retrieved from defaultValueSupplier. Should be removed when StateHelper is extended with similar functionality. (see https://github.com/eclipse-ee4j/mojarra/issues/4568 for details)
      Type Parameters:
      T - the expected type of returned value
      Parameters:
      stateHelper - The stateHelper to try to retrieve value from
      key - The key under which value is stored in the stateHelper
      defaultValueSupplier - The object, from which default value is retrieved
      Returns:
      value from stateHelper or defaultValueSupplier
    • computeIfAbsent

      public static <T> T computeIfAbsent(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)
      Tries to retrieve value from stateHelper by key first. If the value is not present (or is null), then it is retrieved from defaultValueSupplier. Should be removed when StateHelper is extended with similar functionality. (see https://github.com/eclipse-ee4j/mojarra/issues/4568 for details)
      Type Parameters:
      T - the expected type of returned value
      Parameters:
      stateHelper - The stateHelper to try to retrieve value from
      key - The key under which value is stored in the stateHelper
      defaultValueSupplier - The object, from which default value is retrieved
      Returns:
      value from stateHelper or defaultValueSupplier
    • isViewPooling

      public static ComponentUtils.ViewPoolingResetMode isViewPooling(javax.faces.context.FacesContext context)
    • isNestedWithinIterator

      public static boolean isNestedWithinIterator(javax.faces.component.UIComponent component)
      Hack for Mojarra as our UIData is copied from Mojarra. This is required because the way how UIData is implemented in Mojarra requires to check for parent iterator-components.
      Parameters:
      component -
      Returns:
    • encodeIndexedId

      public static void encodeIndexedId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, int index) throws IOException
      GitHub #7763 Renders an in memory UIComponent and updates its ID with an index. For example id="form:test" becomes id="form:test:0".
      Parameters:
      context - the FacesContext.
      component - the UIComponent to render.
      index - the index number to append to the ID
      Throws:
      IOException - if any IO error occurs
    • getDynamicColumnValue

      public static Object getDynamicColumnValue(javax.faces.component.UIComponent component)
    • getDynamicColumnValueAsString

      public static String getDynamicColumnValueAsString(javax.faces.component.UIComponent component)
    • encodeComponent

      public static String encodeComponent(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)
      Encodes the given component locally as HTML.
      Parameters:
      component - The component to capture HTML output for.
      context - The current FacesContext.
      Returns:
      The encoded HTML output of the given component.
      Throws:
      UncheckedIOException - Whenever something fails at I/O level. This would be quite unexpected as it happens locally.
    • executeInRequestScope

      public static <T> T executeInRequestScope(javax.faces.context.FacesContext context, String var, Object value, Supplier<T> callback)
    • getRenderedChildCount

      public static int getRenderedChildCount(javax.faces.component.UIComponent component)
    • isDisabledOrReadonly

      public static boolean isDisabledOrReadonly(javax.faces.component.UIInput component)
    • isUIRepeat

      public static boolean isUIRepeat(javax.faces.component.UIComponent component)