title: Dynamic JSF (2.0) commandButtons - set action with arguments
body: <p>I'm trying to add JSF <code>&lt;h:commandButtons&gt;</code> dynamically to my webpage, and so far I have them displaying, but I cannot set the action with parameters, like I could in a static page:<br>
  <code>action="#{bean.function(parameter)}"</code>.  (this is of course using EL-2.2)<br>
   Looking around I find that I have to create a <code>MethodExpression</code>, but this is obscure to me and I haven't been able to find much information on this. If someone could shine a light through the fog and explain how this can be done, it would be greatly appreciated.</p>
  
  <p>EDIT: so now I have this
  </p>
  
  <pre><code>public void displayNode( String childName ){
  //lots of messy code instantiating JSF components
  
  if( activeEmployee.getParent() != null ){
          HtmlCommandButton parent = new HtmlCommandButton();
          HtmlOutputText parentLabel = new HtmlOutputText();
  
          parentLabel.setId("label" + count++);  //I really hate having to use count
          parentLabel.setValue( "Parent: " );
  
          parent.setId("Parent" + count++); 
          String parentName = activeEmployee.getParent().getName();
          parent.setValue( parentName );
          MethodExpression expression = createMethodExpression("#{tree.displayNode('" + parentName + "')}",
                                                                  null, String.class);
          parent.setActionExpression( expression );
  
          newDiv.getChildren().add( parentLabel );
          newDiv.getChildren().add( parent );
      }
  </code></pre>