有多少 ELResolver[s] is/are 与 JSF 应用程序中的 ELContext 关联?
How many ELResolver[s] is/are associated with an ELContext in a JSF application?
Here 提到
Though only a single ELResolver is associated with an ELContext, there
are usually multiple resolvers considered for any given variable or
property resolution.
为了让回答者能够理解,我在演示它时考虑了自定义 ELResolver。这仅用于说明目的。到目前为止,在我工作的项目中,我还没有觉得需要自制的自定义 ELResolver。
在 CustomELResolver 内部,getValue()
方法看起来像,
@Override
public Object getValue(ELContext ctx, Object base, Object property)
throws NullPointerException, PropertyNotFoundException, ELException {
logger.log(Level.INFO, "Get Value property : {0}", property);
if ((base == null) && property.equals(SOME_PROPERTY)) {
logger.log(Level.INFO, "Found request {0}", base);
ctx.setPropertyResolved(true);
return SOME_OBJECT;
}
return null;
}
Each value expression is evaluated behind the scenes by the getValue
method. Adding this in faces-config.xml, the custom
resolver is added in the chain of responsibility.
一个简单的 facelet 页面:
<h:outputText value="#{bean.name}" />
<br />
<br />
<b>Ordered:</b>
<br />
<h:dataTable id="tableId1"
value="#{PROPERTY DECLARED IN CUSTOM RESOLVER CLASS}" var="t">
<h:column>#{t}</h:column>
</h:dataTable>
和
@ManagedBean(name = "bean")
@RequestScoped
public class Bean {
private String name = "Rafael";
// getters & setters
}
当我调试时,对于上面页面中的这个表达式 value="#{PROPERTY DECLARED IN CUSTOM RESOLVER CLASS}"
,调用委托给 CompositeELResolver
中的 getValue()
,其中 CustomELResolver 被认为是红色突出显示。
然而,对于这个表达式
value="#{bean.name}"
考虑正常ManagedBeanELResolver
。绝对没问题。
但对于同一个请求,ELContext
显然与 2 ELResolvers
相关联。
请说明上述第一段中文档的含义
...a single ELResolver is associated with an ELContext...
您忘记阅读您所指的 link 中的下一句。
ELResolvers are combined together using CompositeELResolvers, to
define rich semantics for evaluating an expression.
如果查看调用层次结构,您会看到 1(一个,一个)FacesCompositeELResolver...所以有一个 CompositeResolver 直接与 ELContext 关联。
但您也可以读到它实际上每次只有一个 EL 解析器在执行工作,'chain' 中的那个表示 "I've resolved it, here is the result"
Here 提到
Though only a single ELResolver is associated with an ELContext, there are usually multiple resolvers considered for any given variable or property resolution.
为了让回答者能够理解,我在演示它时考虑了自定义 ELResolver。这仅用于说明目的。到目前为止,在我工作的项目中,我还没有觉得需要自制的自定义 ELResolver。
在 CustomELResolver 内部,getValue()
方法看起来像,
@Override
public Object getValue(ELContext ctx, Object base, Object property)
throws NullPointerException, PropertyNotFoundException, ELException {
logger.log(Level.INFO, "Get Value property : {0}", property);
if ((base == null) && property.equals(SOME_PROPERTY)) {
logger.log(Level.INFO, "Found request {0}", base);
ctx.setPropertyResolved(true);
return SOME_OBJECT;
}
return null;
}
Each value expression is evaluated behind the scenes by the getValue method. Adding this in faces-config.xml, the custom resolver is added in the chain of responsibility.
一个简单的 facelet 页面:
<h:outputText value="#{bean.name}" />
<br />
<br />
<b>Ordered:</b>
<br />
<h:dataTable id="tableId1"
value="#{PROPERTY DECLARED IN CUSTOM RESOLVER CLASS}" var="t">
<h:column>#{t}</h:column>
</h:dataTable>
和
@ManagedBean(name = "bean")
@RequestScoped
public class Bean {
private String name = "Rafael";
// getters & setters
}
当我调试时,对于上面页面中的这个表达式 value="#{PROPERTY DECLARED IN CUSTOM RESOLVER CLASS}"
,调用委托给 CompositeELResolver
中的 getValue()
,其中 CustomELResolver 被认为是红色突出显示。
然而,对于这个表达式
value="#{bean.name}"
考虑正常ManagedBeanELResolver
。绝对没问题。
但对于同一个请求,ELContext
显然与 2 ELResolvers
相关联。
请说明上述第一段中文档的含义
...a single ELResolver is associated with an ELContext...
您忘记阅读您所指的 link 中的下一句。
ELResolvers are combined together using CompositeELResolvers, to define rich semantics for evaluating an expression.
如果查看调用层次结构,您会看到 1(一个,一个)FacesCompositeELResolver...所以有一个 CompositeResolver 直接与 ELContext 关联。
但您也可以读到它实际上每次只有一个 EL 解析器在执行工作,'chain' 中的那个表示 "I've resolved it, here is the result"