【问题标题】:How to use RichFaces a4j:commandButton not using submit如何使用 RichFaces a4j:commandButton 不使用提交
【发布时间】:2010-03-01 19:00:12
【问题描述】:

我有一个a4j:commandButton,看起来像这样

    <a4j:commandButton id="stopBtn" type="button" reRender="lastOp"
  action="#{MyBacking.stop}" value="Stop" />
 </a4j:commandButton>

部署应用程序并单击按钮时,不会调用 stop() 方法。所有a4j:commandButton 示例都引用表单,但此按钮不在表单中——用户将使用该按钮使服务器运行一些后端逻辑。目前,方法是

    public void stopNode() {
 logger.info("STOPPING");
 setLastOp("Stopped.");
}

其他不使用此类按钮的方法正在更新 lastOp 字段,但我在控制台上没有看到任何内容。我把它作为一个按钮是正确的吗?我应该把它放在h:form 标签中吗?

萤火虫控制台说:

this._form is null

我不明白。

非常感谢任何帮助。

【问题讨论】:

    标签: java jsf richfaces


    【解决方案1】:

    UICommand 组件应该放在UIForm 组件内。所以,你的猜测

    我应该把它放在h:form 标签中吗?

    是完全正确的 :) 这是因为它们触发了 POST 请求,而唯一(正常)的方法是使用 HTML &lt;form&gt; 元素,其 method 属性设置为 "post"。 Firebug 还说应该有一个父表单元素,但它解析为null,因此无法执行任何操作。

    只有像 h:outputLink 和 consorts 这样的“普通”链接不需要表单,因为它们只会触发 GET 请求。

    【讨论】:

      【解决方案2】:

      是的,将其包装在一个表格中。我确信 BalusC 会在我输入答案时发布详细的解释。 (是的,就是这样)

      我不得不问你为什么不先尝试一个表格,然后再在这里发帖。

      【讨论】:

      • 老实说,我同时考虑了两件事,并且在尝试过之后会编辑问题,除非我的工作日结束了,我出门了。 +1 供您观察..
      【解决方案3】:

      看看你的代码:

      <a4j:commandButton id="stopBtn" type="button" reRender="lastOp" action="#{MyBacking.stop}" value="Stop" /> 
      

      你用/&gt;完成了&lt;a4j:commandButton,为什么需要那个孤儿&lt;/a4j:commandButton&gt;

      【讨论】:

        【解决方案4】:

        如果出于某种原因您不想将按钮放在表单中,您可以执行以下操作:

        <a4j:commandButton onclick="fireAjax()"/>
        
        <h:form>
           <a4j:jsFunction name="fireAjax" action=".."/>
        </h:form>
        

        【讨论】:

          猜你喜欢
          • 2011-05-14
          • 2015-03-30
          • 1970-01-01
          • 2014-10-30
          • 2011-06-15
          • 1970-01-01
          • 2012-07-31
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多