Class ComponentUtils


  • public final class ComponentUtils
    extends Object
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static javax.faces.component.UIComponent createComponent​(javax.faces.context.FacesContext facesContext, String componentType, RendererTypes rendererType, String clientId)  
      static void evaluateAutoFor​(javax.faces.component.UIComponent component, Class<? extends javax.faces.component.UIComponent> clazz)
      Looks for the attribute "for" of the component.
      static String evaluateClientId​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String componentId)
      Resolves the real clientId.
      static String evaluateClientIds​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String[] componentIds)
      Resolves the real clientIds.
      static <T> T findAncestor​(javax.faces.component.UIComponent component, Class<T> type)  
      static <T extends javax.faces.component.UIComponent>
      T
      findChild​(javax.faces.component.UIComponent component, Class<T> type)
      Searches the children beneath the component and return the first component matching the type.
      static String findClientIdFor​(javax.faces.component.UIComponent component, javax.faces.context.FacesContext facesContext)
      Looks for the attribute "for" in the component.
      static javax.faces.component.UIComponent findComponent​(javax.faces.component.UIComponent from, String relativeId)
      The search depends on the number of prefixed colons in the relativeId:
      static <T extends javax.faces.component.UIComponent>
      T
      findDescendant​(javax.faces.component.UIComponent component, Class<T> type)
      Searches the component tree beneath the component and return the first component matching the type.
      static <T extends javax.faces.component.UIComponent>
      List<T>
      findDescendantList​(javax.faces.component.UIComponent component, Class<T> type)
      Searches the component tree beneath the component and return all component matching the type.
      static <T extends javax.faces.component.UIComponent>
      T
      findFacetDescendant​(javax.faces.component.UIComponent component, Facets facet, Class<T> type)
      Searches the component tree beneath the component and return the first component matching the type.
      static javax.faces.component.UIComponent findFor​(javax.faces.component.UIComponent component)  
      static AbstractUIFormBase findForm​(javax.faces.component.UIComponent component)  
      static List<javax.faces.component.UIComponent> findLayoutChildren​(javax.faces.component.UIComponent container)  
      static AbstractUIPage findPage​(javax.faces.component.UIComponent component)  
      static AbstractUIPage findPage​(javax.faces.context.FacesContext facesContext)  
      static AbstractUIPage findPage​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)  
      static Object findParameter​(javax.faces.component.UIComponent component, String name)  
      static List<AbstractUIForm> findSubForms​(javax.faces.component.UIComponent component)
      Find all sub forms of a component, and collects it.
      static javax.faces.component.UIViewRoot findViewRoot​(javax.faces.view.facelets.FaceletContext faceletContext, javax.faces.component.UIComponent component)
      Tries to walk up the parents to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for the view root.
      static Object getAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static boolean getBooleanAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static boolean getBooleanAttribute​(javax.faces.component.UIComponent component, Attributes name, boolean defaultValue)  
      static Character getCharacterAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static String getConfirmation​(javax.faces.component.UIComponent component)
      returns the "confirmation" attribute or the value of the "confirmation" facet of a component.
      static Object getConvertedValue​(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component, String stringValue)  
      static javax.faces.convert.Converter getConverter​(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component, Object value)
      May return null, if no converter can be find.
      static Object getDataAttribute​(javax.faces.component.UIComponent component, String name)  
      static Map<Object,​Object> getDataAttributes​(javax.faces.component.UIComponent component)  
      static String getFacesMessageAsString​(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)  
      static javax.faces.component.UIComponent getFacet​(javax.faces.component.UIComponent component, Facets facet)  
      static String getFormattedValue​(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component, Object currentValue)  
      static int getIntAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static int getIntAttribute​(javax.faces.component.UIComponent component, Attributes name, int defaultValue)  
      static javax.faces.application.FacesMessage.Severity getMaximumSeverity​(List<javax.faces.application.FacesMessage> messages)  
      static javax.faces.application.FacesMessage.Severity getMaximumSeverity​(javax.faces.component.UIComponent component)  
      static javax.faces.application.FacesMessage.Severity getMaximumSeverityOfChildrenMessages​(javax.faces.context.FacesContext facesContext, javax.faces.component.NamingContainer container)  
      static AbstractUIReload getReloadFacet​(javax.faces.component.UIComponent component)  
      static RendererBase getRenderer​(javax.faces.context.FacesContext facesContext, String family, String rendererType)  
      static RendererBase getRenderer​(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)  
      static String getStringAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static String getStringAttribute​(javax.faces.component.UIComponent component, Attributes name, String defaultValue)  
      static boolean hasErrorMessages​(javax.faces.context.FacesContext context)
      Deprecated.
      since 3.0.1
      static boolean isError​(javax.faces.component.UIComponent component)  
      static boolean isError​(javax.faces.component.UIInput uiInput)  
      static boolean isFacetOf​(javax.faces.component.UIComponent component, javax.faces.component.UIComponent parent)  
      static boolean isInActiveForm​(javax.faces.component.UIComponent component)
      Deprecated.
      since 4.0.0
      static boolean isInPopup​(javax.faces.component.UIComponent component)
      Deprecated.
      since 3.0.1
      static boolean isOutputOnly​(javax.faces.component.UIComponent component)  
      static Markup markupOfSeverity​(javax.faces.application.FacesMessage.Severity maximumSeverity)  
      static void putDataAttribute​(javax.faces.component.UIComponent component, Object name, Object value)
      Adding a data attribute to the component.
      static void putDataAttributeWithPrefix​(javax.faces.component.UIComponent component, DataAttributes name, Object value)
      Adding a data attribute to the component.
      static void removeAttribute​(javax.faces.component.UIComponent component, Attributes name)  
      static void removeFacet​(javax.faces.component.UIComponent component, Facets facet)  
      static void resetPage​(javax.faces.context.FacesContext context)
      Deprecated.
      since 3.0.1
      static void setAttribute​(javax.faces.component.UIComponent component, Attributes name, Object value)  
      static void setFacet​(javax.faces.component.UIComponent component, Facets facet, javax.faces.component.UIComponent child)  
      static String[] splitList​(String renderers)  
    • Field Detail

      • ACTION_ARGS

        public static final Class[] ACTION_ARGS
      • ACTION_LISTENER_ARGS

        public static final Class[] ACTION_LISTENER_ARGS
      • VALUE_CHANGE_LISTENER_ARGS

        public static final Class[] VALUE_CHANGE_LISTENER_ARGS
      • VALIDATOR_ARGS

        public static final Class[] VALIDATOR_ARGS
      • DATA_ATTRIBUTES_KEY

        public static final String DATA_ATTRIBUTES_KEY
        Name of the map for data attributes in components. New in JSF 2.2.
        Since:
        2.0.0
        See Also:
        Constant Field Values
    • Method Detail

      • hasErrorMessages

        @Deprecated
        public static boolean hasErrorMessages​(javax.faces.context.FacesContext context)
        Deprecated.
        since 3.0.1
      • getFacesMessageAsString

        public static String getFacesMessageAsString​(javax.faces.context.FacesContext facesContext,
                                                     javax.faces.component.UIComponent component)
      • isInPopup

        @Deprecated
        public static boolean isInPopup​(javax.faces.component.UIComponent component)
        Deprecated.
        since 3.0.1
      • resetPage

        @Deprecated
        public static void resetPage​(javax.faces.context.FacesContext context)
        Deprecated.
        since 3.0.1
      • findViewRoot

        public static javax.faces.component.UIViewRoot findViewRoot​(javax.faces.view.facelets.FaceletContext faceletContext,
                                                                    javax.faces.component.UIComponent component)
        Tries to walk up the parents to find the UIViewRoot, if not found, then go to FaceletContext's FacesContext for the view root.
      • findPage

        public static AbstractUIPage findPage​(javax.faces.context.FacesContext context,
                                              javax.faces.component.UIComponent component)
      • findPage

        public static AbstractUIPage findPage​(javax.faces.component.UIComponent component)
      • findPage

        public static AbstractUIPage findPage​(javax.faces.context.FacesContext facesContext)
      • findForm

        public static AbstractUIFormBase findForm​(javax.faces.component.UIComponent component)
      • findAncestor

        public static <T> T findAncestor​(javax.faces.component.UIComponent component,
                                         Class<T> type)
      • findSubForms

        public static List<AbstractUIForm> findSubForms​(javax.faces.component.UIComponent component)
        Find all sub forms of a component, and collects it. It does not find sub forms of sub forms.
      • findDescendant

        public static <T extends javax.faces.component.UIComponent> T findDescendant​(javax.faces.component.UIComponent component,
                                                                                     Class<T> type)
        Searches the component tree beneath the component and return the first component matching the type.
      • findFacetDescendant

        public static <T extends javax.faces.component.UIComponent> T findFacetDescendant​(javax.faces.component.UIComponent component,
                                                                                          Facets facet,
                                                                                          Class<T> type)
        Searches the component tree beneath the component and return the first component matching the type.
      • findChild

        public static <T extends javax.faces.component.UIComponent> T findChild​(javax.faces.component.UIComponent component,
                                                                                Class<T> type)
        Searches the children beneath the component and return the first component matching the type.
      • findDescendantList

        public static <T extends javax.faces.component.UIComponent> List<T> findDescendantList​(javax.faces.component.UIComponent component,
                                                                                               Class<T> type)
        Searches the component tree beneath the component and return all component matching the type.
      • findClientIdFor

        public static String findClientIdFor​(javax.faces.component.UIComponent component,
                                             javax.faces.context.FacesContext facesContext)
        Looks for the attribute "for" in the component. If there is any search for the component which is referenced by the "for" attribute, and return their clientId. If there is no "for" attribute, return the "clientId" of the parent (if it has a parent). This is useful for labels.
      • findFor

        public static javax.faces.component.UIComponent findFor​(javax.faces.component.UIComponent component)
      • evaluateAutoFor

        public static void evaluateAutoFor​(javax.faces.component.UIComponent component,
                                           Class<? extends javax.faces.component.UIComponent> clazz)
        Looks for the attribute "for" of the component. In case that the value is equals to "@auto" the children of the parent will be checked if they are of the type of the parameter clazz. The "id" of the first one will be used to reset the "for" attribute of the component.
      • isInActiveForm

        @Deprecated
        public static boolean isInActiveForm​(javax.faces.component.UIComponent component)
        Deprecated.
        since 4.0.0
      • getMaximumSeverity

        public static javax.faces.application.FacesMessage.Severity getMaximumSeverity​(javax.faces.component.UIComponent component)
      • getMaximumSeverity

        public static javax.faces.application.FacesMessage.Severity getMaximumSeverity​(List<javax.faces.application.FacesMessage> messages)
      • isError

        public static boolean isError​(javax.faces.component.UIInput uiInput)
      • isError

        public static boolean isError​(javax.faces.component.UIComponent component)
      • isOutputOnly

        public static boolean isOutputOnly​(javax.faces.component.UIComponent component)
      • getAttribute

        public static Object getAttribute​(javax.faces.component.UIComponent component,
                                          Attributes name)
      • getBooleanAttribute

        public static boolean getBooleanAttribute​(javax.faces.component.UIComponent component,
                                                  Attributes name)
      • getBooleanAttribute

        public static boolean getBooleanAttribute​(javax.faces.component.UIComponent component,
                                                  Attributes name,
                                                  boolean defaultValue)
      • getStringAttribute

        public static String getStringAttribute​(javax.faces.component.UIComponent component,
                                                Attributes name)
      • getStringAttribute

        public static String getStringAttribute​(javax.faces.component.UIComponent component,
                                                Attributes name,
                                                String defaultValue)
      • getIntAttribute

        public static int getIntAttribute​(javax.faces.component.UIComponent component,
                                          Attributes name)
      • getIntAttribute

        public static int getIntAttribute​(javax.faces.component.UIComponent component,
                                          Attributes name,
                                          int defaultValue)
      • getCharacterAttribute

        public static Character getCharacterAttribute​(javax.faces.component.UIComponent component,
                                                      Attributes name)
      • setAttribute

        public static void setAttribute​(javax.faces.component.UIComponent component,
                                        Attributes name,
                                        Object value)
      • removeAttribute

        public static void removeAttribute​(javax.faces.component.UIComponent component,
                                           Attributes name)
      • getFacet

        public static javax.faces.component.UIComponent getFacet​(javax.faces.component.UIComponent component,
                                                                 Facets facet)
      • setFacet

        public static void setFacet​(javax.faces.component.UIComponent component,
                                    Facets facet,
                                    javax.faces.component.UIComponent child)
      • removeFacet

        public static void removeFacet​(javax.faces.component.UIComponent component,
                                       Facets facet)
      • getReloadFacet

        public static AbstractUIReload getReloadFacet​(javax.faces.component.UIComponent component)
      • isFacetOf

        public static boolean isFacetOf​(javax.faces.component.UIComponent component,
                                        javax.faces.component.UIComponent parent)
      • getRenderer

        public static RendererBase getRenderer​(javax.faces.context.FacesContext facesContext,
                                               javax.faces.component.UIComponent component)
      • getRenderer

        public static RendererBase getRenderer​(javax.faces.context.FacesContext facesContext,
                                               String family,
                                               String rendererType)
      • findParameter

        public static Object findParameter​(javax.faces.component.UIComponent component,
                                           String name)
      • findComponent

        public static javax.faces.component.UIComponent findComponent​(javax.faces.component.UIComponent from,
                                                                      String relativeId)

        The search depends on the number of prefixed colons in the relativeId:

        number of prefixed colons == 0
        fully relative
        number of prefixed colons == 1
        absolute (still normal findComponent syntax)
        number of prefixed colons == 2
        search in the current naming container (same as 0 colons)
        number of prefixed colons == 3
        search in the parent naming container of the current naming container
        number of prefixed colons > 3
        go to the next parent naming container for each additional colon

        If a literal is specified: to use more than one identifier the identifiers must be space delimited.

      • evaluateClientIds

        public static String evaluateClientIds​(javax.faces.context.FacesContext context,
                                               javax.faces.component.UIComponent component,
                                               String[] componentIds)
        Resolves the real clientIds.
      • evaluateClientId

        public static String evaluateClientId​(javax.faces.context.FacesContext context,
                                              javax.faces.component.UIComponent component,
                                              String componentId)
        Resolves the real clientId.
      • splitList

        public static String[] splitList​(String renderers)
      • getConvertedValue

        public static Object getConvertedValue​(javax.faces.context.FacesContext facesContext,
                                               javax.faces.component.UIComponent component,
                                               String stringValue)
      • markupOfSeverity

        public static Markup markupOfSeverity​(javax.faces.application.FacesMessage.Severity maximumSeverity)
      • getMaximumSeverityOfChildrenMessages

        public static javax.faces.application.FacesMessage.Severity getMaximumSeverityOfChildrenMessages​(javax.faces.context.FacesContext facesContext,
                                                                                                         javax.faces.component.NamingContainer container)
      • putDataAttributeWithPrefix

        public static void putDataAttributeWithPrefix​(javax.faces.component.UIComponent component,
                                                      DataAttributes name,
                                                      Object value)
        Adding a data attribute to the component. The name must start with "data-", e. g. "data-tobago-foo" or "data-bar"
      • putDataAttribute

        public static void putDataAttribute​(javax.faces.component.UIComponent component,
                                            Object name,
                                            Object value)
        Adding a data attribute to the component. The name should not start with "data-", e. g. "tobago-foo" or "bar"
      • getDataAttributes

        public static Map<Object,​Object> getDataAttributes​(javax.faces.component.UIComponent component)
      • getDataAttribute

        public static Object getDataAttribute​(javax.faces.component.UIComponent component,
                                              String name)
      • getConverter

        public static javax.faces.convert.Converter getConverter​(javax.faces.context.FacesContext facesContext,
                                                                 javax.faces.component.UIComponent component,
                                                                 Object value)
        May return null, if no converter can be find.
      • getFormattedValue

        public static String getFormattedValue​(javax.faces.context.FacesContext facesContext,
                                               javax.faces.component.UIComponent component,
                                               Object currentValue)
                                        throws javax.faces.convert.ConverterException
        Throws:
        javax.faces.convert.ConverterException
      • createComponent

        public static javax.faces.component.UIComponent createComponent​(javax.faces.context.FacesContext facesContext,
                                                                        String componentType,
                                                                        RendererTypes rendererType,
                                                                        String clientId)
      • findLayoutChildren

        public static List<javax.faces.component.UIComponent> findLayoutChildren​(javax.faces.component.UIComponent container)
      • getConfirmation

        public static String getConfirmation​(javax.faces.component.UIComponent component)
        returns the "confirmation" attribute or the value of the "confirmation" facet of a component.
        Since:
        Tobago 4.4.0