Package de.xima.fc.gui.util
Class ComponentAttribute<T>
- java.lang.Object
-
- de.xima.fc.gui.util.ComponentAttribute<T>
-
- Type Parameters:
T- The expected type of the attribute value.
public final class ComponentAttribute<T> extends Object
Helper class reading and writing attributes of a FacesUIComponent.This class encapsulates the logic for accessing attributes of components, whether they are defined as literal attributes or as value expressions. Intended to be used as part of component implementations, especially for composite components.
- Since:
- 8.5.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classComponentAttribute.Builder<T>Builder for creating instances ofComponentAttributewith a fluent API for configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.el.MethodExpressionasMethodExpression(Class<?> returnType, Class<?>... paramTypes)Gets the attribute as a method expression with the specified return type and parameter types.javax.el.ValueExpressionasValueExpression()Gets the attribute as a value expression.static <T> ComponentAttribute.Builder<T>builder(javax.faces.component.UIComponent component, String attributeName, Class<T> type)Creates a builder for a component attribute with the specified name and expected type.static <T> ComponentAttribute.Builder<List<T>>builderForList(javax.faces.component.UIComponent component, String attributeName, Class<T> type)Creates a builder for a component attribute that is expected to be a list of a specific type.javax.el.ValueExpressionconvertToValueExpression()Converts the attribute to a value expression.Tget()Retrieves the current value of the attribute.<R> Rinvoke(Class<R> returnType, Class<?>[] paramTypes, Object... params)Invokes the method defined by this attribute as a method expression with the specified return type and parameter types, using the provided parameters.voidset(T value)Updates the attribute value and synchronizes it with the underlying data model.
-
-
-
Method Detail
-
asMethodExpression
public javax.el.MethodExpression asMethodExpression(Class<?> returnType, Class<?>... paramTypes)
Gets the attribute as a method expression with the specified return type and parameter types. If the attribute does not define a method expression, returns null.- Parameters:
returnType- The expected return type of the method expressionparamTypes- The expected parameter types of the method expression- Returns:
- The method expression if defined and compatible, or null otherwise.
-
asValueExpression
public javax.el.ValueExpression asValueExpression()
Gets the attribute as a value expression. If the attribute does not define a value expression, returns null.- Returns:
- The value expression if defined, or null otherwise.
-
convertToValueExpression
public javax.el.ValueExpression convertToValueExpression()
Converts the attribute to a value expression. If the attribute is defined as a literal attribute, it is wrapped in a literal value expression. If the attribute is not defined at all, returns null.- Returns:
- The value expression representing the attribute, or null if the attribute is not defined.
-
get
public T get()
Retrieves the current value of the attribute.The value is dynamically resolved during each call to ensure synchronization with the current JSF context and component state.
- Returns:
- The resolved value of type
T. - Throws:
javax.el.PropertyNotFoundException- If the property is missing or null, and eitherthrowOnMissingValueorthrowOnNullValueis enabled.IllegalArgumentException- if the resolved value is null or of an incompatible type.
-
invoke
public <R> R invoke(Class<R> returnType, Class<?>[] paramTypes, Object... params)
Invokes the method defined by this attribute as a method expression with the specified return type and parameter types, using the provided parameters.- Type Parameters:
R- The expected return type of the method expression.- Parameters:
returnType- The expected return type of the method expressionparamTypes- The expected parameter types of the method expressionparams- The parameters to pass to the method expression when invoking it.- Returns:
- The result of the method expression invocation, cast to the specified return type.
- Throws:
javax.el.MethodNotFoundException- If no compatible method expression is found for the attribute with the specified return type and parameter types.
-
set
public void set(T value)
Updates the attribute value and synchronizes it with the underlying data model.If a
ValueExpressionis associated with this attribute, the method attempts to update the source bean directly. If no expression is found, the value is stored in the component's local attribute map, and a warning is logged.- Parameters:
value- The new value to set.- Throws:
javax.el.PropertyNotWritableException- If the property is not writable andthrowOnNonWritablePropertyis enabled.
-
builder
public static <T> ComponentAttribute.Builder<T> builder(javax.faces.component.UIComponent component, String attributeName, Class<T> type)
Creates a builder for a component attribute with the specified name and expected type. The builder allows configuring various options for how the attribute is accessed and manipulated, such as initial value suppliers and error handling behavior.- Type Parameters:
T- The expected type of the attribute value.- Parameters:
component- The component for which to create the attribute builder.attributeName- The name of the attribute to access on the component.type- The expected type of the attribute value, used for type checking and casting.- Returns:
- A builder for creating a ComponentAttribute instance with the specified configuration.
-
builderForList
public static <T> ComponentAttribute.Builder<List<T>> builderForList(javax.faces.component.UIComponent component, String attributeName, Class<T> type)
Creates a builder for a component attribute that is expected to be a list of a specific type. This is a convenience method since Java does not allow class literals for parameterized types (e.g. List<String>.class is not valid).- Type Parameters:
T- The expected type of the attribute value.- Parameters:
component- The component for which to create the attribute builder.attributeName- The name of the attribute to access on the component.type- The expected type of the list elements, used for type checking and casting of the list contents.- Returns:
- A builder for creating a ComponentAttribute instance with the specified configuration.
-
-