Package org.primefaces.util
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 classComponentUtils.ViewPoolingResetMode
-
Field Summary
Fields Modifier and Type Field Description static StringSKIP_ITERATION_HINTstatic Set<javax.faces.component.visit.VisitHint>VISIT_HINTS_SKIP_UNRENDERED
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringcalculateViewId(javax.faces.context.FacesContext context)Calculates the current viewId - we can't get it from the ViewRoot if it's not available.static <T> TcomputeIfAbsent(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)Tries to retrieve value from stateHelper by key first.static StringcreateContentDisposition(String value, String filename)Creates an RFC 6266 Content-Dispostion header following all UTF-8 conventions.static voiddecodeBehaviors(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)static StringencodeURI(String string)Duplicate code from OmniFacew project under apache license: https://github.com/omnifaces/omnifaces/blob/develop/license.txtstatic StringescapeSelector(String selector)static <T> Teval(javax.faces.component.StateHelper stateHelper, Serializable key, Supplier<T> defaultValueSupplier)Tries to retrieve value from stateHelper by key first.static javax.faces.application.NavigationCasefindNavigationCase(javax.faces.context.FacesContext context, String outcome)static StringgetConvertedAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)static ObjectgetConvertedValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, Object value)static javax.faces.convert.ConvertergetConverter(javax.faces.context.FacesContext context, Class<?> forClass)static javax.faces.convert.ConvertergetConverter(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)Finds appropriate converter for a given value holderstatic ObjectgetLabel(javax.faces.context.FacesContext facesContext, javax.faces.component.UIComponent component)static Map<String,List<String>>getUIParams(javax.faces.component.UIComponent component)static <T extends javax.faces.render.Renderer>
TgetUnwrappedRenderer(javax.faces.context.FacesContext context, String family, String rendererType)static StringgetValueToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)static StringgetValueToRender(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 returnedstatic booleaninvokeOnClosestIteratorParent(javax.faces.component.UIComponent component, Consumer<javax.faces.component.UIComponent> function, boolean includeSelf)static booleanisFlex(javax.faces.context.FacesContext context, FlexAware component)static booleanisNestedWithinIterator(javax.faces.component.UIComponent component)static booleanisRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)static booleanisRequestSource(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context, String event)static booleanisRTL(javax.faces.context.FacesContext context, RTLAware component)static booleanisSkipIteration(javax.faces.component.visit.VisitContext visitContext, javax.faces.context.FacesContext context)static booleanisTouchable(javax.faces.context.FacesContext context, TouchAware component)static ComponentUtils.ViewPoolingResetModeisViewPooling(javax.faces.context.FacesContext context)static voidprocessDecodesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)static voidprocessUpdatesOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)static voidprocessValidatorsOfFacetsAndChilds(javax.faces.component.UIComponent component, javax.faces.context.FacesContext context)static booleanshouldRenderChildren(javax.faces.component.UIComponent component)Checks if the component's children are renderedstatic booleanshouldRenderFacet(javax.faces.component.UIComponent facet)Checks if the facet and one of the first level children is rendered.static booleanshouldRenderFacet(javax.faces.component.UIComponent facet, boolean ignoreChildren)Checks if the facet and one of the first level children is rendered.
-
-
-
Field Detail
-
VISIT_HINTS_SKIP_UNRENDERED
public static final Set<javax.faces.component.visit.VisitHint> VISIT_HINTS_SKIP_UNRENDERED
-
SKIP_ITERATION_HINT
public static final String SKIP_ITERATION_HINT
- See Also:
- Constant Field Values
-
-
Method Detail
-
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 instancecomponent- UIComponent instance whose value will be returnedvalue- 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 instancecomponent- ValueHolder instance to look converter for- Returns:
- Converter
-
getConvertedValue
public static Object getConvertedValue(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 value)
-
getConverter
public static javax.faces.convert.Converter getConverter(javax.faces.context.FacesContext context, Class<?> forClass)
-
decodeBehaviors
public static void decodeBehaviors(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
-
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- TheFacesContext.- 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.txtURI-encode the given string using UTF-8. URIs (paths and filenames) have different encoding rules as compared to URL query string parameters.
URLEncoderis 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
nullifnullwas 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 ignoreChildren)Checks if the facet and one of the first level children is rendered.- Parameters:
facet- The Facet component to checkignoreChildren- 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 whenStateHelperis 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 fromkey- The key under which value is stored in the stateHelperdefaultValueSupplier- 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 whenStateHelperis 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 fromkey- The key under which value is stored in the stateHelperdefaultValueSupplier- The object, from which default value is retrieved- Returns:
- value from stateHelper or defaultValueSupplier
-
isNestedWithinIterator
public static boolean isNestedWithinIterator(javax.faces.component.UIComponent component)
-
invokeOnClosestIteratorParent
public static boolean invokeOnClosestIteratorParent(javax.faces.component.UIComponent component, Consumer<javax.faces.component.UIComponent> function, boolean includeSelf)
-
isViewPooling
public static ComponentUtils.ViewPoolingResetMode isViewPooling(javax.faces.context.FacesContext context)
-
-