{
if (bean instanceof IModel) {
bean = ((IModel)bean).getObject();
}
Component component = element.getBeanMetaData().getComponent();
String methodName = element.getActionMethodName();
try {
// Try first to find a bean-specific method.
Method method;
try {
method = component.getClass().getMethod(methodName, new Class[] { AjaxRequestTarget.class, Form.class, bean.getClass() } );
}
catch (Exception e) {
// Ignore and try generic parameters.
method = component.getClass().getMethod(methodName, GENERIC_ACTION_PARAMS);
}
method.invoke(component, new Object[] { target, form, bean });
}
catch (NoSuchMethodException e) {
throw new RuntimeException("Action method " + methodName + "(AjaxRequestTarget, Form, " + bean.getClass().getName() + "/Object) is not defined in " + component.getClass());
}
catch (IllegalAccessException e) {
throw new RuntimeException("Action method " + methodName + " defined in " + component.getClass() + " must be declared public");
}
catch (InvocationTargetException e) {
throw new RuntimeException("Error invoking action " + methodName + " defined in " + component.getClass(), e.getCause());
}
}