什么是 <f:ajax execute="@all">真的应该怎么办?它只发布封闭的表单 [英] What is <f:ajax execute="@all"> really supposed to do? It POSTs only the enclosing form

查看:15
本文介绍了什么是 <f:ajax execute="@all">真的应该怎么办?它只发布封闭的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,如果我太粗了,但是 f:ajax 标签中的 execute="@all" 真的应该做什么?我希望它提交页面上的所有元素,但它似乎只发布封闭表单中的值,而不是页面上的所有表单.

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.

例如

<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>

点击后仅发布 form2.

Only form2 is posted on click.

使用 mojarra 2.0.2..

Using mojarra 2.0.2..

推荐答案

execute=@all" 只是在设计 JSF2 规范过程中的一个重大疏忽.JSF 抽象了太多基于 HTML 表单的特性,忘记了它最终实际上是一个 HTML 代码生成器.

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.

HTML 中,提交与封闭的不允许.所以 execute="@all" 永远不会从这个角度工作.它的行为与 execute="@form" 完全相同.鉴于 JSF 只是一个 HTML 代码生成器,同样的问题"出现了.也会击中 JSF.一次处理多个 组件是不可能的.

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 表单的错误方式.您需要确保表单的设计方式使您永远不需要来自其他表单的信息.

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.

PrimeFaces 很早就意识到 @all根本上错了.这就是为什么他们从不支持 process 属性中的 @all,它们相当于 execute.他们最初也从未在 update 中支持 @all,它们相当于 render.然而,唯一有意义的真实用例是在 ajax 异常期间处理完整的错误页面,所以他们最终在我创建 FullAjaxExceptionHandler.process=@all" 仍然具有与 process=@form" 完全相同的效果.

PrimeFaces already realized early that @all was fundamentally wrong. That's exactly why they never supported @all in process attribute, their equivalent of execute. They initially also never supported @all in 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 库也无意中通过其后来引入的 partialSubmit=true" 功能,您可以在其中明确指定所有其他形式,如下所示(PFS @(form) 只是为了简化,硬编码:formId1 :formId2 :formId3 等集合也是可能的.

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 :formId3 etc is also just possible).

<p:commandButton ... process="@(form)" partialSubmit="true" />

这是有效的,因为 partialSubmit="true" 在客户端而不是服务器端准备 process="xxx".换句话说,它不是将整个封闭表单从服务器发送到客户端然后处理指定的输入,而是仅将指定的输入从服务器发送到客户端,然后处理它们.请注意,当 partialSubmit 不存在或设置为 false 时,它仍然只会发送封闭表单.不应该依赖这种不当行为.他们迟早可能会纠正这种不当行为.

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 partialSubmit is 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.

这篇关于什么是 &lt;f:ajax execute="@all"&gt;真的应该怎么办?它只发布封闭的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆