<h:commandbutton>不调用方法</h:commandbutton>

时间:2013-11-15 13:24:38

标签: jsf action managed-bean commandbutton

我有<h:commandButton>

   <f:metadata>
        <f:viewParam name="uri" value="#{pesquisaBean.selectedUri}" />
        <f:event listener="#{pesquisaBean.searchElement()}" type="preRenderView"></f:event>
    </f:metadata>
    <h:head>
        <title>Detalhes do Documento</title>
    </h:head>

       <h:body>
       <br />
       Detalhes do Documento

       <br />
       <br />
       <rich:dataTable value="#{pesquisaBean.documentDetailsByTitle}" var="result">

                <c:forEach items="#{pesquisaBean.variableNamesDetails}" var="vname">
                     <rich:column>
                         <f:facet name="header">#{vname}</f:facet>
                          #{result[vname]}
                     </rich:column> 

                </c:forEach> 
       </rich:dataTable>
       <br />
       <h:commandButton value="Excluir" action="#{pesquisaBean.delete()}" />
       <br />
       <br />

和这个行动方法

  public void delete() {
    System.out.println("Hello");
    this.removeDocument(databaseModel, this.selectedDocument);

    System.out.println("");
    System.out.println("After deleting!!!!!!!!!!!!");
    StmtIterator result = databaseModel.listStatements();
    while( result.hasNext() ) {
        Statement stmt = result.next();
        System.out.println(stmt);
    }

但是,命令按钮不会调用操作方法。 我正在尝试在方法的第一行打印Hello,但不打印。

这是如何引起的?如何解决?

1 个答案:

答案 0 :(得分:10)

我猜,您没有将<h:commandButton/><h:form/>括起来。尝试打电话:

<h:form>
  <h:commandButton value="Excluir" action="#{pesquisaBean.delete()}" />
</h:form>

每当您使用JSF时,始终通过在context-param中编写web.xml来开放开发环境。

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

它会显示警告,xhtml中缺少什么。