Java 如何使用 RichFaces a4j:commandButton 不使用提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2358292/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use RichFaces a4j:commandButton not using submit
提问by volvox
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. 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. At the moment, the method is
部署应用程序并单击按钮时,不会调用 stop() 方法。所有a4j:commandButton
示例都引用了表单,但此按钮不是在表单中 - 它是用户将用来使服务器运行某些后端逻辑的按钮。目前的方法是
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. Am I right to cast this as a button? Should I put this in a h:form
tag?
其他不使用此类按钮的方法正在更新 lastOp 字段,但我在控制台上没有看到任何带有此按钮的方法。我把它当作一个按钮是对的吗?我应该把它放在一个h:form
标签中吗?
The firebug console says:
萤火虫控制台说:
this._form is null
which I don't understand.
我不明白。
Any help well appreciated.
任何帮助都非常感谢。
采纳答案by BalusC
UICommand
components ought to be placed inside an UIForm
component. So, your guess
UICommand
组件应该放在UIForm
组件内。所以,你的猜测
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"
. Firebug also says that a parent form element is been expected, but it resolved to null
and thus no actions can be taken place.
是完全正确的:)这是因为他们火了POST
请求,并为使用HTML只(正常)的方法<form>
元素,其method
属性设置为"post"
。Firebug 还表示需要父表单元素,但它已解决null
,因此无法执行任何操作。
Only "plain vanilla" links like h:outputLink
and consorts doesn't need a form, because they just fires a GET
request.
只有像h:outputLink
和 consorts 这样的“普通”链接不需要表单,因为它们只是触发一个GET
请求。
回答by Naganalf
Yes, wrap it in a form. I'm sure BalusC will post a detailed explanation while I'm typing my answer. (yup, there it is)
是的,把它包装成一个表格。我确定 BalusC 会在我输入答案时发布详细说明。(是的,它在那里)
I have to ask why you didn't just try a form first, before posting here.
我不得不问你为什么不先尝试一个表格,然后再在这里发帖。
回答by Max tay
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
与/>
,为什么需要一个孤儿</a4j:commandButton>
?
回答by Max Katz
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>