简体   繁体   English

如何使用RichFaces a4j:commandButton不使用submit

[英]How to use RichFaces a4j:commandButton not using submit

I have an a4j:commandButton which looks like this 我有一个a4j:commandButton ,看起来像这样

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

When the app is deployed, and the button clicked, the stop() method is not being called. 部署应用程序并单击按钮时,不会调用stop()方法。 All the a4j:commandButton examples refer to forms, but this button is not in a form - it's a button the user is going to use to cause the server to run some back-end logic. 所有a4j:commandButton示例都引用表单,但此按钮不在表单中 - 它是用户将用于使服务器运行某些后端逻辑的按钮。 At the moment, the method is 目前,方法是

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

Other methods which don't use this type of button are updating the lastOp field, but I'm not seeing anything on the console with this one. 不使用这种类型按钮的其他方法是更新lastOp字段,但我没有在控制台上看到任何这个。 Am I right to cast this as a button? 我是否正确将其作为按钮投射? Should I put this in a h:form tag? 我应该把它放在一个h:form标签中吗?

The firebug console says: firebug控制台说:

this._form is null

which I don't understand. 我不明白。

Any help well appreciated. 任何帮助很好的赞赏。

UICommand components ought to be placed inside an UIForm component. UICommand组件应该放在UIForm组件中。 So, your guess 所以,你的猜测

Should I put this in a h:form tag? 我应该把它放在一个h:form标签中吗?

is entirely correct :) This because they fire a POST request and the only (normal) way for that is using a HTML <form> element whose method attribute is set to "post" . 完全正确:)这是因为它们触发了一个POST请求,唯一的(正常)方式是使用一个HTML <form>元素,其method属性设置为"post" Firebug also says that a parent form element is been expected, but it resolved to null and thus no actions can be taken place. Firebug还表示期望父表单元素,但它解析为null ,因此不能执行任何操作。

Only "plain vanilla" links like h:outputLink and consorts doesn't need a form, because they just fires a GET request. 只有像h:outputLinkh:outputLink这样的“普通香草”链接不需要表单,因为它们只是触发GET请求。

Yes, wrap it in a form. 是的,将其包裹在表格中。 I'm sure BalusC will post a detailed explanation while I'm typing my answer. 我确定BalusC会在我输入答案时发布详细解释。 (yup, there it is) (是的,那里)

I have to ask why you didn't just try a form first, before posting here. 在发布之前,我不得不问你为什么不先尝试表格。

Look at your code: 看看你的代码:

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

You finished <a4j:commandButton with /> , why need that orphan </a4j:commandButton> ? 你用/>完了<a4j:commandButton ,为什么需要那个orphan </a4j:commandButton>

If for some reason you don't want to place the button inside a form, you can do something like this: 如果由于某种原因您不想将按钮放在表单中,您可以执行以下操作:

<a4j:commandButton onclick="fireAjax()"/>

<h:form>
   <a4j:jsFunction name="fireAjax" action=".."/>
</h:form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM