Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create action for HtmlCommandLink#setActionExpression()

Tags:

jsf-2

I am trying to add commandlink programatically, but I am not able to add action.

HtmlCommandLink link = new HtmlCommandLink();
link.setValue(data);
link.setActionExpression(no idea);

How do I create it?

like image 696
Pallavi Avatar asked Jul 03 '26 07:07

Pallavi


1 Answers

Use ExpressionFactory#createMethodExpression().

Here's a convenience method:

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

Here's how you could use it, provided that you've a public String doSomething() {} action in a managed bean identified by #{bean}:

link.setActionExpression(createMethodExpression("#{bean.doSomething}", String.class));
like image 137
BalusC Avatar answered Jul 05 '26 17:07

BalusC