【发布时间】:2016-02-11 00:28:10
【问题描述】:
我有复合组件:
<my:component value="#{bean.property1.property2}/>
我需要从复合组件中获取 bean.property1 类来读取它的注释。
我通过以下代码做到这一点:
ValueExpression valueExpression = expressionFactory.createValueExpression(FacesContext.getCurrentInstance().getELContext(),
"#{bean.property1}", Object.class);
Object bean = valueExpression.getValue(FacesContext.getCurrentInstance().getELContext());
Class<?> beanClass = bean.getClass();
这很好用,但是如果我使用 facelet 中的 my:component 并通过 ui:param 将 bean 作为参数传递,这将不起作用,因为无法解析 bean。
也许我应该使用FaceletContext 作为ELContext 而不是FacesContext.getCurrentInstance().getELContext():
FaceletContext faceletElContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes()
.get("javax.faces.FACELET_CONTEXT");
但这不适用于RENDER_RESPONSE 阶段(来自encodeBegin 方法)。它返回最后使用的 ELContext 而不是实际上下文(我并不感到惊讶 :))。
目标是从my:component 获得#{bean.property1} 的类。我该怎么做?
【问题讨论】:
标签: jsf jsf-2 facelets composite-component