Friday, December 17, 2010

Resolving Method expression programmatically In JSF

EL is used in JSF to bind java methods with userinterface actions like commandbutton and commandlink. But sometimes It is needed to resolve method binding programmatically. Sample method can be used for this purpose:

public static Object resloveMethodExpression(String expression,
Class returnType,
Class[] argTypes,
Object[] argValues) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
MethodExpression methodExpression =
elFactory.createMethodExpression(elContext, expression, returnType,
return methodExpression.invoke(elContext, argValues);

No comments:

Post a Comment