1

我有一个与此类似的复合标签:

<ui:decorate template="....">
   <ui:define name="...">
       <h:inputText value="#{value}"/>
   </ui:define>
</ui:decorate>

它用于类似的页面

<ns:tag value="#{some.el.expression}"/>

It works fine as it is. Now I want to access the "some.el.expression" from java code. I need something similiar to component.getValueExpression("value") . It doesn't seems to work, if I cann it on the inputText node it give me "#{value}" which is not what I want. I am couldn't figure a way to access this value. Any thoughts?

4

1 回答 1

2

You can use Application#evaluateExpressionGet() to evaluate an EL expression programmatically.

FacesContext context = FacesContext.getCurrentInstance();
Object value = context.getApplication().evaluateExpressionGet(
    context, "#{some.el.expression}", Object.class);

Where Object.class can be substituted by the real return type. Note that whatever it returns is dependent on the exact moment when you're evaluating the expression. It might not be in the EL scope yet, or it might already have been removed from the EL scope.

于 2012-08-30T20:45:58.147 回答