title: How to invoke a managed bean function from an autogenerated command button with ajax
body: <p>I have a h:selectOneMenu jsf tag that contains a list of users to pick one. When I select one option a h:dataTable is generated using ajax. This new dataTable contains two columns: the user information (picked) and a button to delete that row (user).
  The behavior expected is that when I click on Delete button that rows must be deleted. But when I click on Delete commandButton the method attached to it (delete) doesn't work. Debugging code delete method never start.
  I see the source code generated on the browser and I saw that the table is generated with no rows. I'm not sure if that's the error. Must I use another html tag? How can I execute a backing bean method from an auto generated dom elements.</p>
  
  <p>the code of my facelet is next:</p>
  
  <pre><code>&lt;h:selectOneMenu id="artifactAuthors" value="#{artifactBean.authorId}" required="true"&gt;
    &lt;f:selectItems value="#{artifactBean.users}"/&gt;
  &lt;/h:selectOneMenu&gt;
  &lt;h:commandButton value="Add" type="button"&gt;
    &lt;f:ajax listener="#{artifactBean.addAuthor}" execute="artifactAuthors" render="selectedAuthors"/&gt;
  &lt;/h:commandButton&gt;
  &lt;h:panelGroup id="selectedAuthors"&gt;
    &lt;h:dataTable value="#{artifactBean.selectedAuthors.entrySet().toArray()}" var="author"&gt;
      &lt;h:column&gt;&lt;h:outputLabel value="#{author.key}"/&gt;&lt;/h:column&gt;
      &lt;h:column&gt;
        &lt;h:commandButton value="#{bundle['button.delete']}" type="button"&gt;
          &lt;f:ajax listener="#{artifactBean.delete(1)}" render="selectedAuthors"/&gt;
        &lt;/h:commandButton&gt;
      &lt;/h:column&gt;
    &lt;/h:dataTable&gt;
  &lt;/h:panelGroup&gt;
  </code></pre>
  
  <p>An the backing bean is next:</p>
  
  <pre><code>@Named(value = "artifactBean")
  @RequestScoped
  public class ArtifactBean {
  ...
    Map&lt;String, Integer&gt; selectedAuthors;
  ...
  
    public void delete(int id) {
      System.out.println("==&gt; "+id);
      int a = 3;
      int b = 2;
      int c = a * b;
    }
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/y2F71.png" rel="nofollow">This is the form sreenshot</a></p>
  
  <p>Thanks in advance.</p>