什么是< f:ajax execute =" @ all>>真的应该做吗?它仅过帐封闭表格 [英] What is <f:ajax execute="@all"> really supposed to do? It POSTs only the enclosing form

查看:148
本文介绍了什么是< 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.不可能一次处理多个<h:form>组件.

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属性(等同于execute)中的@all的原因.最初,他们也从不支持update中的@all(等同于render).但是,在现实世界中唯一有意义的用例是在ajax异常期间处理完整的错误页面,因此在我创建仍将与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库也通过后来引入的execute="@all"的预期行为成为可能> partialSubmit="true" 功能,通过该功能您可以明确指定所有其他形式,如下所示(

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.

  • Any significant technical difference between JSF non-AJAX submit and a "@all" AJAX submit?
  • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes

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

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