且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取托管bean,并绑定到"value"类型.属性

更新时间:2022-01-12 18:25:03

UIComponent 提供 getValueExpression("attributeName")

样本:

  UIViewRoot viewRoot = Faces.getViewRoot();
            UIComponent component= viewRoot.findComponent("x");
            ValueExpression value = component.getValueExpression("value");
            Class<?> expectedType = value.getType(Faces.getELContext());

NB: Faces 摘自 Omnifaces ,它是"JSF API实用程序方法的集合,主要用于以下方面的快捷方式:从线程本地FacesContext获取内容."

NB:Faces here is from Omnifaces, which is a "Collection of utility methods for the JSF API that are mainly shortcuts for obtaining stuff from the thread local FacesContext. "

getType() javadoc

公共抽象类getType(ELContext context)评估相对于所提供上下文的表达式,并返回最可以作为对象传递的对象可接受的常规类型将来对setValue(javax.el.E​​LContext.java.lang.Object)方法的调用中的value参数.这并不总是与getValue().getClass().例如,对于表达式而言,引用数组元素,getType方法将返回数组的元素类型,它可能是该类型的超类当前在指定数组元素中的实际元素.

public abstract Class getType(ELContext context) Evaluates the expression relative to the provided context, and returns the most general type that is acceptable for an object to be passed as the value parameter in a future call to the setValue(javax.el.ELContext. java.lang.Object) method. This is not always the same as getValue().getClass(). For example, in the case of an expression that references an array element, the getType method will return the element type of the array, which might be a superclass of the type of the actual element that is currently in the specified array element.

对于 MethodExpression ,请阅读此内容.