<f:ajax execute="@all"> 真正应该做什么?它只发布封闭的表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2999101/
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
What is <f:ajax execute="@all"> really supposed to do? It POSTs only the enclosing form
提问by dave
sorry if I am being thick but what is the execute="@all" in an f:ajax tag really supposed to do? I expected it to submit all the elements on a page but it seems to POST only the values in the enclosing form, not all forms on page.
对不起,如果我很厚,但是 f:ajax 标签中的 execute="@all" 真的应该做什么?我希望它提交页面上的所有元素,但它似乎只发布封闭表单中的值,而不是页面上的所有表单。
For example
例如
<h:body>
<h:form id="form1">
Input1/Form1 <h:inputText id="testinput" value="#{testBean.input1}" />
</h:form>
<h:form id="form2">
Input2/form2 <h:inputText id="testinput2" value="#{testBean.input2}" />
<h:commandButton value="Ok" actionListener="#{testBean.al}">
<f:ajax execute="@all" />
</h:commandButton>
</h:form>
</h:body>
Only form2 is posted on click.
单击时仅发布 form2。
Using mojarra 2.0.2..
使用 mojarra 2.0.2..
回答by BalusC
The execute="@all"was just a major oversight during designing JSF2 spec. JSF kind of abstracted away too much of its HTML form based nature, forgetting that it's ultimately actually a HTML code generator.
这execute="@all"只是在设计 JSF2 规范期间的一个重大疏忽。JSF 抽象了太多基于 HTML 表单的性质,忘记了它最终实际上是一个 HTML 代码生成器。
In HTML, submitting a different form than the enclosing one is disallowed. So execute="@all"will never work from that perspective on. It will behave exactly the same as execute="@form". Given that JSF is just a HTML code generator, the same "problem" will hit JSF too. It's not possible to process multiple <h:form>components at once.
在HTML 中,不允许提交与封闭表单不同的表单。所以execute="@all"永远不会从那个角度工作。它的行为与execute="@form". 鉴于 JSF 只是一个 HTML 代码生成器,同样的“问题”也会影响到 JSF。<h:form>一次处理多个组件是不可能的。
If you really need to have this feature for some reason, you should take a step back and reconsider the incorrect way how you look at HTML forms. You need to make sure your forms are designed in such way that you never need information from another form.
如果出于某种原因确实需要使用此功能,则应该退后一步,重新考虑查看 HTML 表单的错误方式。您需要确保表单的设计方式使您永远不需要来自其他表单的信息。
See also:
也可以看看:
PrimeFaces already realized early that @allwas fundamentally wrong. That's exactly why they never supported @allin processattribute, their equivalent of execute. They initially also never supported @allin update, their equivalent of render. However, the only real world use case where that made sense was handling a full error page during an ajax exception, so they ultimately brought update="@all"back after I created the FullAjaxExceptionHandler. The process="@all"will still have exactly the same effect as process="@form".
PrimeFaces 早就意识到这@all是根本错误的。这正是为什么他们从来没有支持@all的process属性,它们的等效的execute。最初,他们还从来没有支持@all的update,其当量render。然而,现实世界中唯一有意义的用例是在 ajax 异常期间处理完整的错误页面,因此它们最终update="@all"在我创建FullAjaxExceptionHandler. 该process="@all"会仍然有完全一样的效果相同process="@form"。
However, the very same PrimeFaces library also unintentionally made the imagined behavior of execute="@all"possible via its later introduced partialSubmit="true"feature whereby you explicitly specify all other forms like below (the PFS@(form)is just for simplification, a hardcoded collection like :formId1 :formId2 :formId3etc is also just possible).
然而,同样的 PrimeFaces 库也无意中execute="@all"通过其后来引入的partialSubmit="true"功能使想象中的行为成为可能,您可以明确指定所有其他形式,如下所示(PFS@(form)只是为了简化,硬编码的集合:formId1 :formId2 :formId3等也是可能的)。
<p:commandButton ... process="@(form)" partialSubmit="true" />
This works because partialSubmit="true"prepares the process="xxx"at client side rather than server side. In other words, instead of sending the entire enclosing form from server to client and then processing the specified inputs, it sends only the specified inputs from server to client and then processes them all. Do note that when partialSubmitis absent or set to false, then it would still only send the enclosing form. This misbehavior should rather not be relied upon. They may fix this misbehavior on their side sooner or later.
这是有效的,因为partialSubmit="true"准备process="xxx"在客户端而不是服务器端。换句话说,它不是将整个封闭表单从服务器发送到客户端然后处理指定的输入,而是仅将指定的输入从服务器发送到客户端,然后处理它们。请注意,当partialSubmit不存在或设置为 时false,它仍然只会发送封闭表格。不应该依赖这种不当行为。他们迟早可能会纠正这种不当行为。
See also:
也可以看看:
回答by Tuukka Mustonen
Here is a quote from JavaServer Faces 2.0 - The complete reference, page 352:
这里引用了JavaServer Faces 2.0 - 完整参考,第 352 页:
The execute and render keywords accept a set of special keywords, each with the meaning shown in this table:
@all (using with
execute): Every component on the page is submittedand processed. This is useful when you want to do a full-page submit.
execute 和 render 关键字接受一组特殊关键字,每个关键字的含义如下表所示:
@all(使用 with
execute):页面上的每个组件都被提交和处理。当您想要进行整页提交时,这很有用。
I think this quite clearly states that the fields from all forms should be submitted with the AJAX request.
我认为这很清楚地表明所有表单中的字段都应该与 AJAX 请求一起提交。
However, even with Mojarra 2.0.3 this doesn't happen. Despite of contents of the executeattribute (whether you put a list of forms or @all) only the enclosing form gets its' fields submitted. So this seems like a bug. I am raising an issue about this unless there are altering views?
但是,即使使用 Mojarra 2.0.3,这也不会发生。尽管execute属性的内容(无论是放置表单列表还是@all),只有封闭的表单才能提交其字段。所以这似乎是一个错误。除非有不同的观点,否则我正在提出一个关于此的问题?
回答by dave
It would have to be execute=":form1 form2" (if you have the default separator), but anyway no, it doesn't. It only sends the second one.
它必须是 execute=":form1 form2"(如果您有默认分隔符),但无论如何不,它没有。它只发送第二个。
If you put @all in the first form, it only sends the first. At least on Safari 5/Firefox 3.6.3 anyway. I guess one would have to look at the mojarra javascript to find out more.
如果你把@all 放在第一个表单中,它只会发送第一个。至少在 Safari 5/Firefox 3.6.3 上。我想人们必须查看 mojarra javascript 才能了解更多信息。
回答by Vítor E. Silva Souza
Have you tried this?
你试过这个吗?
<f:ajax execute="form1 form2" />
Does it send both forms' data if you explicitly mention them?
如果您明确提及它们,它是否会发送两个表单的数据?
AFAIK, you are right: @all represents the whole page.
AFAIK,你是对的:@all 代表整个页面。

