title: MethodExpression IllegalArgumentException: wrong number of arguments
body: <p>I've got a JSF page that is rendered dynamically - all components are created by the backing bean and added to a grid. I have a command button that I've created a MethodExpression to set the method to call when the button is clicked. But clicking the button results in the exceptions "java.lang.IllegalArgumentException: wrong number of arguments" and "javax.faces.FacesException: wrong number of arguments".</p>
  
  <p>The code that creates the button is</p>
  
  <pre><code>HtmlCommandButton addBtn1 = (HtmlCommandButton) FacesContext.getCurrentInstance().
  getApplication().createComponent(HtmlCommandButton.COMPONENT_TYPE);
  addBtn1.setId("addBtn1");
  addBtn1.setValue("Add Row");
  String addBtn1Action = "#{dynamicComponentTest.addBtn1_action}";
  Class[] args = new Class[]{ActionEvent.class};
  MethodExpression addBtn1ME = FacesContext.getCurrentInstance().getApplication().
  getExpressionFactory().createMethodExpression(
  FacesContext.getCurrentInstance().getELContext(), addBtn1Action, null, args);
  addBtn1.setActionExpression(addBtn1ME);
  mainGrid.getChildren().add(addBtn1);
  </code></pre>
  
  <p>Then the action method's signature is</p>
  
  <pre><code>public String addBtn1_action(ActionEvent event)
  </code></pre>
  
  <p>When I run my test app and click the button, I get the exceptions. However, if I change the signature to</p>
  
  <pre><code>public String addBtn1_action(ActionEvent[] event)
  </code></pre>
  
  <p>I get a MethodNotFoundException where it can't find "...DynamicComponentTest@1db3b45.addBtn1_action(javax.faces.event.ActionEvent)"</p>
  
  <p>Has anyone succesfully solved this issue? I have tried both null and String.class as the type of the return value in the createMethodExpression and that doesn't help solve it.</p>