EL 表达式通常用于指定页面上 ADF Faces 组件的属性值。有趣的是,我们可以使用 component 关键字来引用正在评估 EL 表达式的组件实例。这有点类似于 Java 中的 this 。
例如,在下面的代码片段中,按钮的 hint 被评估为按钮的 text 值,并且其 visible 属性将由支持返回接受组件作为参数的 bean 方法:
<af:button text="#{theBean.buttonText}" id="b1" shortDesc="#{component.text}" visible="#{theBean.isVisible(component)}"/>
支持 bean 方法可能如下所示:
public boolean isVisible(UIComponent button) { //Do something with the button ((RichButton) button).setIcon("images/awesomeIcon.jpg"); //check button's attributes if (button. ...) return true; else return false; }
当涉及到在某些迭代器(或列表视图或表等)中渲染组件时,这种技术可能非常有用,我们需要根据确切的组件实例动态评估组件的属性值。
就是这样!
标签2: Java教程地址:https://www.cundage.com/article/jcg-referring-adf-faces-component-el-expression.html