Java:
public class MyBean {
...
public Handler getHandler(){
return new Handler(){
public void handle(ActionEvent e){...}
}
}
...
}
public interface Handler{
void handle(ActionEvent e);
}
xhtml:
<h:commandButton ... actionListener="#{myBean.handler.handle}"/>
I’m in a tomcat 6.0 environment. This is a common pattern in java, but it seems not to work with EL method bindings. I get an exception:
javax.faces.event.MethodExpressionActionListener processAction SEVERE): Received 'java.lang.IllegalAccessException' when invoking action listener '#{myBean.handler.handle}' for component 'j_id115'
javax.faces.event.MethodExpressionActionListener processAction SEVERE): java.lang.IllegalAccessException: Class org.apache.el.parser.AstValue can not access a member of class MyBean$1 with modifiers "public"
...
This was more subtle than I thought…
From java, there is no problem calling the public method in the inner class:
Using reflection, it depends on how it’s done. The method can be invoked as declared (1):
Or it can be invoked as defined in the inner class (2):
Obviously, there’s a third option, and it works (3):
Unfortunately, my JSF environment (Tomcat 6.0 with JSF mojarra 1.2 and icefaces 1.8.2) implements approach (2) instead of (3) and therefore my example doesn’t work.