Package org.primefaces.util
Class ComponentUtils
java.lang.Object
org.primefaces.util.ComponentUtils
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 Object
convertToType
(Object value, Class<?> valueType, Logger logger) static String
createContentDisposition
(String value, String filename) 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
Duplicate code from OmniFaces project under apache license: https://github.com/omnifaces/omnifaces/blob/develop/license.txtstatic String
escapeSelector
(String selector) 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) Executes a callback within the request scope, optionally storing and restoring a value in the FacesContext request map.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 holderstatic 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>
TgetUnwrappedRenderer
(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 returnedstatic boolean
isDisabledOrReadonly
(javax.faces.component.UIInput component) static boolean
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
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 <E extends Throwable>
voidrunWithoutFacesContextVar
(javax.faces.context.FacesContext context, String var, Callbacks.FailableRunnable<E> runnable) Execute a callback in a stateless scope by temporarily removing and restoring a variable from the FacesContext attributes.static boolean
shouldRenderChildren
(javax.faces.component.UIComponent component) Checks if the component's children are renderedstatic boolean
shouldRenderFacet
(javax.faces.component.UIComponent facet) Deprecated.use FacetUtilsstatic boolean
shouldRenderFacet
(javax.faces.component.UIComponent facet, boolean alwaysRender) Deprecated.use FacetUtilsstatic javax.faces.convert.Converter
toConverter
(javax.faces.context.FacesContext context, Object converter)
-
Field Details
-
VISIT_HINTS_SKIP_UNRENDERED
-
VISIT_HINTS_SKIP_ITERATION
-
-
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 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 up converter for- Returns:
- Converter
-
getConvertedValue
-
getConvertedValue
-
getConvertedAsString
-
getConvertedAsString
-
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 converter) -
decodeBehaviors
public static void decodeBehaviors(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) -
escapeSelector
-
isRTL
-
isTouchable
-
isFlex
-
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) -
getUIParams
-
isSkipIteration
public static boolean isSkipIteration(javax.faces.component.visit.VisitContext visitContext, javax.faces.context.FacesContext context) -
getUnwrappedRenderer
-
calculateViewId
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
Duplicate code from OmniFaces 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.
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
ifnull
was given. - Throws:
UnsupportedEncodingException
- if UTF-8 is not supported
-
createContentDisposition
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
@Deprecated public static boolean shouldRenderFacet(javax.faces.component.UIComponent facet, boolean alwaysRender) Deprecated.use FacetUtilsChecks if the facet and one of the first level children is rendered.- Parameters:
facet
- The Facet component to checkalwaysRender
- flag to ignore children and only check the facet itself- Returns:
- true if the facet should be rendered, false if not
-
shouldRenderFacet
Deprecated.use FacetUtilsChecks 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 whenStateHelper
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 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 whenStateHelper
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 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
-
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
- theFacesContext
.component
- theUIComponent
to render.index
- the index number to append to the ID- Throws:
IOException
- if any IO error occurs
-
getDynamicColumnValue
-
getDynamicColumnValueAsString
-
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) Executes a callback within the request scope, optionally storing and restoring a value in the FacesContext request map. If no variable name is provided, the callback is executed without storing or restoring any value.- Type Parameters:
T
- The type of result returned by the callback.- Parameters:
context
- The FacesContext associated with the current request.var
- The name of the variable to store in the FacesContext request map. If null or empty, the callback is executed without storing or restoring any value.value
- The value to store in the FacesContext request map under the given variable name. If null, no value is stored.callback
- A Supplier representing the callback to execute within the request scope.- Returns:
- The result of executing the callback.
-
runWithoutFacesContextVar
public static <E extends Throwable> void runWithoutFacesContextVar(javax.faces.context.FacesContext context, String var, Callbacks.FailableRunnable<E> runnable) throws E Execute a callback in a stateless scope by temporarily removing and restoring a variable from the FacesContext attributes.- Type Parameters:
E
- The type of Throwable that may be thrown- Parameters:
context
- The FacesContext used for accessing attributesvar
- The variable to be temporarily removed and restored in the context attributesrunnable
- The callback to be executed- Throws:
E
- If the callback throws an exception of type E
-
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) -
convertToType
-