【问题标题】:JSF / RichFaces - How to call programatically an ActionEvent from HtmlAjaxSupport (a4j:support)JSF / RichFaces - 如何以编程方式从 HtmlAjaxSupport (a4j:support) 调用 ActionEvent
【发布时间】:2014-01-31 18:17:00
【问题描述】:

我正在这样做

htmlAjaxSupport.setActionExpression(createMethodExpression(
                        "#{questionarioMB.visualizarQuestoesFilhos}", null,
                        new Class[0]));

方法

public void visualizarQuestoesFilhos()

被调用。

但我想打电话

 public void visualizarQuestoesFilhos(ActionEvent event)

因为这样,我可以知道哪个组件被点击了。

我需要在 htmlAjaxSupport设置什么才能工作?

【问题讨论】:

标签: java jsf richfaces


【解决方案1】:

在 JSF 1.2 或更新版本中创建 ActionListener 表达式:

FacesContext context = FacesContext.getCurrentInstance();
MethodExpression actionListener = context.getApplication().getExpressionFactory()
    .createMethodExpression(context.getELContext(), "#{bean.actionListener}", null, new Class[] {ActionEvent.class});
uiCommandComponent.addActionListener(new MethodExpressionActionListener(actionListener));

为避免大量样板代码,您可以将其很好地包装在辅助方法中(如果需要,在辅助/实用程序类中),例如:

public static MethodExpression createAction(String actionExpression, Class<?> returnType) {
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getApplication().getExpressionFactory()
        .createMethodExpression(context.getELContext(), actionExpression, returnType, new Class[0]);
}

public static MethodExpressionActionListener createActionListener(String actionListenerExpression) {
    FacesContext context = FacesContext.getCurrentInstance();
    return new MethodExpressionActionListener(context.getApplication().getExpressionFactory()
        .createMethodExpression(context.getELContext(), actionListenerExpression, null, new Class[] {ActionEvent.class}));
}

从 Adrian 提供的另一个 stackoverthread 获取 sn-p:

Deprecated richfaces javax.faces.el.MethodBinding replacement use

【讨论】:

    猜你喜欢
    • 2011-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-15
    • 2015-06-07
    • 1970-01-01
    相关资源
    最近更新 更多