EL中的#{component}到底是什么? [英] What exactly is #{component} in EL?

查看:127
本文介绍了EL中的#{component}到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 https://code.google.com/p/primefaces/issues/detail?id = 4720 ComponentUtils.resolveWidgetVar(String expression, UIComponent component)函数从2013年开始在Primefaces中可用.可以通过"#{p:widgetVarFromContext(searchExpression, component)}"函数在EL中使用.

According to https://code.google.com/p/primefaces/issues/detail?id=4720, The ComponentUtils.resolveWidgetVar(String expression, UIComponent component) function is available in Primefaces since 2013. It can be used in EL by the "#{p:widgetVarFromContext(searchExpression, component)}" function.

这在多个组件在不同的NamingContainer中具有相同的id,但仍存在于同一视图中的情况下很有用.在这种情况下, #{p:widgetVar(searchExpression)}函数仅返回找到的最后一个.

This is useful in case of several components have the same id in different NamingContainer, but are still present in the same view. In this case, the #{p:widgetVar(searchExpression)} function only returns the last one found.

但是我不明白如何引用必须作为EL第二个参数传递的UIComponent.上面提到的错误报告建议我们可以使用#{component}来引用它.谁能给我一个例子?

I don't understand however how to reference the UIComponent that must be passed as the second argument from EL. The above mentioned bug report suggests we can refer to it using #{component}. Can anyone provide me with an example?

推荐答案

#{component}是隐式EL变量,引用了

The #{component} is an implicit EL variable referring the current UIComponent in EL scope (see also implicit EL objects). You can usually only refer it in component's HTML attribute or in template text children.

例如如果是<h:inputText>,它将引用 UIInput 类,其中除其他外还具有isValid()方法.

E.g. in case of <h:inputText> it will reference an instance of UIInput class which has among others an isValid() method.

<h:inputText id="foo" required="true"
    style="background: #{component.valid ? '' : 'pink'}"
    onclick="alert('Client ID of this component is #{component.clientId}');" />

您还可以使用binding属性,使JSF在视图构建期间将对Facelet范围内的组件实例的引用放在引用中.这样,在视图渲染期间,组件引用将在Facelet中的任何位置可用.

You can also use binding attribute to let JSF during view build time put a reference to a component instance in the Facelet scope. This way the component reference will be available anywhere in the Facelet during view render time.

<script>alert('Client ID of foo component is #{foo.clientId}');</script>
<h:inputText binding="#{foo}" />

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆