title: JSF commandButton not working when created dynamically with java
body: <p>Using primeFaces I have the following button:</p>
  
  <pre><code>&lt;p:commandButton value="Submit" action="#{createDeal.saveDeal}" update="myPanel" /&gt;
  </code></pre>
  
  <p>This works just fine.  However I want to generate that button using java.
  I have the following code:</p>
  
  <pre><code>CommandButton submit = new CommandButton();
  submit.setValue("Submit");
  submit.setUpdate("myPanel");
  FacesContext facesCtx = FacesContext.getCurrentInstance();
  Application app = facesCtx.getApplication();
  ExpressionFactory elFactory = app.getExpressionFactory();
  ELContext elContext = facesCtx.getELContext();
  MethodExpression methodExpression =null;
  methodExpression = elFactory.createMethodExpression(elContext,"#{createDeal.saveDeal}",String.class, new Class[]{});
  submit.addActionListener(new MethodExpressionActionListener(methodExpression));
  submit.setActionExpression(methodExpression);
  createButtons.getChildren().add(submit);
  </code></pre>
  
  <p>When I click submit, my form validates (which is done using the setRequired function on the input), but the form never hits my createDeal class.  What am I doing wrong that the inline button works, but the java generated one does not.  </p>
  
  <p>One note.  The button created inline using primefaces, is there on page load.  The button attempted to be added with java is not done until after an Ajax call is made to generate both the form AND button.</p>
  
  <p>Any assistance would be helpful.</p>
  
  <p>Thanks.</p>