首页 > 解决方案 > 从阶段侦听器(beforePhase 或 afterPhase)访问 adf 中页面片段的 UI 组件

问题描述

我是 Oracle ADF 的新手,当 JSPX 的阶段侦听器运行时,我需要帮助才能访问 JSPX 文件上的页面片段的 UI 组件。

我有这个 .jspx 文件,其中包含一个af:region。该区域连接到页面片段(.jsff)文件,我想从 JSPX 文件的页面阶段侦听器(beforePhase 或 afterPhase 事件)访问页面片段内部的 UI 组件(例如 inputText 等) .

页面片段绑定到 pageFlowScope bean 及其所有 UI 组件。但是当我尝试从阶段侦听器事件中访问 bean 时,绑定到 bean 的 UI 组件尚未初始化并返回 NullPointerException。

我现在正在考虑尝试通过阶段侦听器事件的“id”访问 UI 组件。这可能吗?

标签: jsfjsf-2oracle-adf

解决方案


您可以直接从视图页面 El Expression 检索绑定的 inputText 或阶段侦听器中的任何其他 ADF 组件的值。这是一个简单的例子:https ://cedricleruth.com/how-to-retreive-the-value-of-an-iterator-binding-variable-programmatically-in-adf/

在你的情况下,它看起来像:

//Below is a view example with values taken from an ADF View Object. Don't forget to add an MVCE next time
//<af:inputText id="it1" autoSubmit="true" value="#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}" />

public static void YOUR_PHASE_EVENT(PhaseEvent pe) {
    String inputTextValue= (String)this.resolveExpression("#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}");
    //Do whatever you want with it
}

/**
 * Method for taking a reference to a JSF binding expression and returning
 * the matching object (or creating it).
 * @param expression EL expression
 * @return Managed object
 * @author : Duncan Mills, Steve Muench and Ric Smith's JSFUtils class
 */
public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
    return valueExp.getValue(elContext);
}

推荐阅读