如何从带有ajax的自动生成的命令按钮调用托管bean函数

时间:2016-03-06 05:50:48

标签: jsf dom facelets

我有一个h:selectOneMenu jsf标记,其中包含一个用户列表。当我选择一个选项时,使用ajax生成h:dataTable。这个新的dataTable包含两列:用户信息(拾取)和删除该行(用户)的按钮。 预期的行为是,当我单击“删除”按钮时,必须删除行。但是当我点击Delete commandButton时,附加到它的方法(删除)不起作用。调试代码删除方法永远不会启动。 我看到在浏览器上生成的源代码,我看到生成的表没有行。我不确定这是不是错误。我必须使用另一个html标签吗?如何从自动生成的dom元素执行辅助bean方法。

我的facelet的代码是下一个:

<h:selectOneMenu id="artifactAuthors" value="#{artifactBean.authorId}" required="true">
  <f:selectItems value="#{artifactBean.users}"/>
</h:selectOneMenu>
<h:commandButton value="Add" type="button">
  <f:ajax listener="#{artifactBean.addAuthor}" execute="artifactAuthors" render="selectedAuthors"/>
</h:commandButton>
<h:panelGroup id="selectedAuthors">
  <h:dataTable value="#{artifactBean.selectedAuthors.entrySet().toArray()}" var="author">
    <h:column><h:outputLabel value="#{author.key}"/></h:column>
    <h:column>
      <h:commandButton value="#{bundle['button.delete']}" type="button">
        <f:ajax listener="#{artifactBean.delete(1)}" render="selectedAuthors"/>
      </h:commandButton>
    </h:column>
  </h:dataTable>
</h:panelGroup>

下一个支持bean:

@Named(value = "artifactBean")
@RequestScoped
public class ArtifactBean {
...
  Map<String, Integer> selectedAuthors;
...

  public void delete(int id) {
    System.out.println("==> "+id);
    int a = 3;
    int b = 2;
    int c = a * b;
  }
}

This is the form sreenshot

提前致谢。

0 个答案:

没有答案
相关问题