Package de.xima.fc.gui.util
Class ComponentHelper
- java.lang.Object
- 
- de.xima.fc.gui.util.ComponentHelper
 
- 
 public class ComponentHelper extends Object Utility methods for working withUIComponents.- Author:
- XIMA MEDIA GmbH
 
- 
- 
Constructor SummaryConstructors Constructor Description ComponentHelper()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddCssDevResource(String id, String fileName, String libraryName, String devPath)static voidaddCssResource(String id, String fileName, String libraryName)Dynamically adds a CSS resource to the current page.static voidaddJsDevResource(String id, String fileName, String libraryName, String devPath)static voidaddJsResource(String id, String fileName, String libraryName)Dynamically adds a JavaScript resource to the current page.static voidaddRenderId(String clientId)Adds the givencomponentclient IDto the set ofrender IDsof the given faces context, e.g. causing those components to update during the render phase.static voidaddRenderId(javax.faces.context.FacesContext context, String clientId)Adds the givencomponentclient IDto the set ofrender IDsof the given faces context, e.g. causing those components to update during the render phase.static voidappendJsonObject(org.primefaces.util.WidgetBuilder wb, IFastJsonConverter converter, Object data, Object defaultValue)Serializes the given object viaJSONExceptionand appends the result to the widget builder.static <T> voidappendWidgetConfig(javax.faces.context.FacesContext context, org.primefaces.util.WidgetBuilder wb, IWidgetConfigProviding<T> config)Serializes the given config viaJSONand appends the result to the widget builder.static StringbuildAjaxRequest(javax.faces.context.FacesContext context, javax.faces.component.UIComponent source, org.primefaces.component.api.AjaxSource ajaxSource, String event)static <T> Tclosest(javax.faces.component.UIComponent base, Class<T> targetClass)Similar toComponentTraversalUtils.closest(Class, UIComponent)andComponents.getClosestParent(UIComponent, Class), but with the difference that this method returns the given base if the base already matches the target type.static <T> Tclosest(javax.faces.component.UIComponent base, Class<T> targetClass, Predicate<T> filter)Similar toComponentTraversalUtils.closest(Class, UIComponent)andComponents.getClosestParent(UIComponent, Class), but with the difference that (a) this method returns the given base if the base already matches the target type, and (b) that this method lets you specifiy a custom filter function that target must match.static voidexecuteAjaxRequest(javax.faces.context.FacesContext context, javax.faces.component.UIComponent source, CustomAjaxSource ajaxSource, String event)static Class<?>getClassFromAttribute(javax.faces.view.facelets.TagAttribute typeTagAttribute, javax.faces.view.facelets.TagAttribute loaderTagAttribute, javax.faces.view.facelets.FaceletContext ctx)static String[]getIdChain(javax.faces.component.UIComponent component)static StringgetIdChainString(javax.faces.component.UIComponent component)static booleanhasInvokedSubmit(javax.faces.component.UIComponent component)Similar toComponents.hasInvokedSubmit(UIComponent), but with a hacky fix for composite components that implementcc:clientBehavior.static <TRetVal> TRetValinvokeMethod(javax.faces.context.FacesContext context, javax.el.MethodExpression method, Class<TRetVal> expectedReturnType, Object... args)Invokes a JSF method expression with the given arguments, and casts the result to the expected type.static booleanisAnyParentScheduledToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent base)static voidremoveFromScheduledToRender(javax.faces.context.FacesContext context, String clientId)static voidremoveSelfAndAllParentsScheduledToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent base, String resolvedClientId)Removes any parent of the given UI component (not including that given component) that is scheduled to be rendered (updated) from the components to be rendered.static <T extends javax.faces.event.SystemEventListener & IIdChainProviding>
 voidremoveViewListeners(javax.faces.context.FacesContext context, Class<? extends javax.faces.event.SystemEvent> systemEventType, Class<T> listenerType, javax.faces.component.UIComponent component)
 
- 
- 
- 
Method Detail- 
addCssDevResourcepublic static void addCssDevResource(String id, String fileName, String libraryName, String devPath) 
 - 
addCssResourcepublic static void addCssResource(String id, String fileName, String libraryName) Dynamically adds a CSS resource to the current page. Should be called before the actual rendering phase. Usually this is called from aUIComponentduringPostAddToViewEvent.- Parameters:
- id- ID of the resource. Used to prevent it from being added multiple times.
- fileName- File name of the resource.
- libraryName- Library of the resource. May be- nullor empty when no library should be used.
 
 - 
addJsDevResourcepublic static void addJsDevResource(String id, String fileName, String libraryName, String devPath) 
 - 
addJsResourcepublic static void addJsResource(String id, String fileName, String libraryName) Dynamically adds a JavaScript resource to the current page. Should be called before the actual rendering phase. Usually this is called from aUIComponentduringPostAddToViewEvent.- Parameters:
- id- ID of the resource. Used to prevent it from being added multiple times.
- fileName- File name of the resource.
- libraryName- Library of the resource. May be- nullor empty when no library should be used.
 
 - 
addRenderIdpublic static void addRenderId(javax.faces.context.FacesContext context, String clientId)Adds the givencomponentclient IDto the set ofrender IDsof the given faces context, e.g. causing those components to update during the render phase. Makes sure not to add client IDs that were already added.- Parameters:
- context- Current faces context.
- clientId- Client ID to add.
 
 - 
addRenderIdpublic static void addRenderId(String clientId) Adds the givencomponentclient IDto the set ofrender IDsof the given faces context, e.g. causing those components to update during the render phase. Makes sure not to add client IDs that were already added.- Parameters:
- clientId- Client ID to add.
 
 - 
appendJsonObjectpublic static void appendJsonObject(org.primefaces.util.WidgetBuilder wb, IFastJsonConverter converter, Object data, Object defaultValue) throws IOException, FastJsonExceptionSerializes the given object viaJSONExceptionand appends the result to the widget builder.- Parameters:
- wb- Widget builder to which the properties are appended.
- converter- The JSON converter to use for converting between objects and JSON.
- data- An object with data to append to the widget builder.
- defaultValue- An object with the default data. This is used to omit properties whose value is equal to the default. This reduces the amount of data that needs to be sent to the client. When- null, this mechanism is disabled.
- Throws:
- IOException- When the given widget builder throws an- IOException.
- FastJsonException- When the JSON could not be converted.
 
 - 
appendWidgetConfigpublic static <T> void appendWidgetConfig(javax.faces.context.FacesContext context, org.primefaces.util.WidgetBuilder wb, IWidgetConfigProviding<T> config) throws IOExceptionSerializes the given config viaJSONand appends the result to the widget builder.- Type Parameters:
- T- Type of the widget configuration.
- Parameters:
- context- The current faces context to be used.
- wb- Widget builder to which the properties are appended.
- config- A provider for the data to append to the widget builder.
- Throws:
- IOException- When the given widget builder throws an- IOException.
 
 - 
buildAjaxRequestpublic static String buildAjaxRequest(javax.faces.context.FacesContext context, javax.faces.component.UIComponent source, org.primefaces.component.api.AjaxSource ajaxSource, String event) 
 - 
closestpublic static <T> T closest(javax.faces.component.UIComponent base, Class<T> targetClass)Similar toComponentTraversalUtils.closest(Class, UIComponent)andComponents.getClosestParent(UIComponent, Class), but with the difference that this method returns the given base if the base already matches the target type.- Type Parameters:
- T- Type of the target component.
- Parameters:
- base- Base component where to start.
- targetClass- Type of the target component.
- Returns:
- The first parent of the given type. If the given base is already of the given type, the base is returned.
 
 - 
closestpublic static <T> T closest(javax.faces.component.UIComponent base, Class<T> targetClass, Predicate<T> filter)Similar toComponentTraversalUtils.closest(Class, UIComponent)andComponents.getClosestParent(UIComponent, Class), but with the difference that (a) this method returns the given base if the base already matches the target type, and (b) that this method lets you specifiy a custom filter function that target must match.- Type Parameters:
- T- Type of the target component.
- Parameters:
- base- Base component where to start.
- targetClass- Type of the target component.
- filter- Filter to apply to the components.
- Returns:
- The first parent of the given type that matches the given filter. If the given base is already of the given type and matches the filter, the base is returned.
 
 - 
executeAjaxRequestpublic static void executeAjaxRequest(javax.faces.context.FacesContext context, javax.faces.component.UIComponent source, CustomAjaxSource ajaxSource, String event)
 - 
getClassFromAttributepublic static Class<?> getClassFromAttribute(javax.faces.view.facelets.TagAttribute typeTagAttribute, javax.faces.view.facelets.TagAttribute loaderTagAttribute, javax.faces.view.facelets.FaceletContext ctx) 
 - 
getIdChainpublic static String[] getIdChain(javax.faces.component.UIComponent component) 
 - 
getIdChainStringpublic static String getIdChainString(javax.faces.component.UIComponent component) 
 - 
hasInvokedSubmitpublic static boolean hasInvokedSubmit(javax.faces.component.UIComponent component) Similar toComponents.hasInvokedSubmit(UIComponent), but with a hacky fix for composite components that implementcc:clientBehavior.- Parameters:
- component- The component to be checked.
- Returns:
- trueif the given component has invoked the form submit.
 
 - 
invokeMethodpublic static <TRetVal> TRetVal invokeMethod(javax.faces.context.FacesContext context, javax.el.MethodExpression method, Class<TRetVal> expectedReturnType, Object... args)Invokes a JSF method expression with the given arguments, and casts the result to the expected type. Returnsnullin case of an error.- Type Parameters:
- TRetVal- Type of the expected return value of the method expression.
- Parameters:
- context- Faces context to use.
- method- Method expression to invoke.
- expectedReturnType- Expected return type of the method expression. Use- Voidfor no return value.
- args- Optional arguments to pass to the method expression.
- Returns:
- The value returned by the method expression.
 
 - 
isAnyParentScheduledToRenderpublic static boolean isAnyParentScheduledToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent base)- Parameters:
- context- Current faces context.
- base- Base component in the component tree where to start.
- Returns:
- trueif any parent of the given UI component (not including that given component) is scheduled to be rendered (updated), or- falseotherwise.
 
 - 
removeFromScheduledToRenderpublic static void removeFromScheduledToRender(javax.faces.context.FacesContext context, String clientId)
 - 
removeSelfAndAllParentsScheduledToRenderpublic static void removeSelfAndAllParentsScheduledToRender(javax.faces.context.FacesContext context, javax.faces.component.UIComponent base, String resolvedClientId)Removes any parent of the given UI component (not including that given component) that is scheduled to be rendered (updated) from the components to be rendered. Adds back all siblings that would have been rendered by virtue of a parent being rendered.- Parameters:
- context- Current faces context.
- base- Base component in the component tree where to start.
- resolvedClientId- The full client ID of the component, resulting from a full tree visit (e.g. respecting ui:repeat etc.).
 
 - 
removeViewListenerspublic static <T extends javax.faces.event.SystemEventListener & IIdChainProviding> void removeViewListeners(javax.faces.context.FacesContext context, Class<? extends javax.faces.event.SystemEvent> systemEventType, Class<T> listenerType, javax.faces.component.UIComponent component) 
 
- 
 
-