我正在做这个
htmlAjaxSupport.setActionExpression(createMethodExpression(
"#{questionarioMB.visualizarQuestoesFilhos}", null,
new Class[0]));
方法
public void visualizarQuestoesFilhos()
被召唤。
但我想打电话
public void visualizarQuestoesFilhos(ActionEvent event)
因为这样,我可以获得点击哪个组件。
htmlAjaxSupport 中设置需要什么才能正常工作?
答案 0 :(得分: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));
为了避免大量的样板代码,你可以很好地将它包装在辅助方法中(如果需要在helper / utility类中),例如:
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提供的另一个stackovetraread获取片段:
Deprecated richfaces javax.faces.el.MethodBinding replacement use