12

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.

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.

Using mojarra 2.0.2..

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
dave
  • 121
  • 1
  • 1
  • 3
  • 2
    This one has me stumped. If execute="@form" execute's all inputs within the form, one would assume @all would do more than the form, ie. all the forms. – Brian Leathem Jun 10 '10 at 02:46
  • Confusing indeed. Check http://java.net/jira/browse/JAVASERVERFACES-1719 and http://java.net/jira/browse/JAVASERVERFACES-1908 Yet to be resolved I guess. – Tuukka Mustonen Jan 10 '11 at 07:20
  • The JIRA cases noted are closed as incomplete, and works as designed. – John Yeary Dec 10 '12 at 18:31

4 Answers4

10

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.

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.

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.

See also:


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

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

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.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you, BalusC, for answering my question http://stackoverflow.com/q/34372095/4142984 by adding an answer here. It does not, however, suggest any workaround yet. I don't have any deep understanding of the javascript involved on client side, but what would be fundamentally wrong with just collecting all the relevant input data into the Httml-request automatically by f:ajax? – Gyro Gearloose Dec 19 '15 at 16:44
  • @ BalusC: what alternatives do you suggest to what you rightfully call bad practice (every workaround is bad practice! )? – Gyro Gearloose Dec 19 '15 at 16:52
  • As for what I intend to use it, that's http://stackoverflow.com/q/34182816/4142984 . I would like to transfer the modifier mask to the server. And the suggested answers as of right now would force me to put an individual h:inputHidden into every component that would use it instead of have one singleton h:form inputHidden that could be used by every component that requires this feature. – Gyro Gearloose Dec 19 '15 at 17:01
  • @ BallusC, I'm really a newbie, so excuse my if I don't understand your suggestion. Just to check: as I read it, you are suggesting that I should place the functionality on browser-dependent javascript and/or write my own facelets? – Gyro Gearloose Dec 19 '15 at 17:09
  • "In your question you're specifically asking for a workaround", well, not really. I only complained that there was no workaround given to avoid the ubiquitous marking everything as duplicate. What I asked was: "Any ideas what I am doing wrong or how that could be fixed?" – Gyro Gearloose Dec 19 '15 at 18:29
  • @ BalusC: I was only a little alarmed as you updated this question here without even leaving a comment on my question that points to this one. – Gyro Gearloose Dec 21 '15 at 14:29
  • @Gyro: it wasn't an answer to your question. – BalusC Dec 21 '15 at 14:34
  • It wasn't as I still don't know what to do instead, but then again it was because your answer here is to stop trying to do this completely. – Gyro Gearloose Dec 21 '15 at 14:38
4

Here is a quote from JavaServer Faces 2.0 - The complete reference, page 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 submitted and processed. This is useful when you want to do a full-page submit.

I think this quite clearly states that the fields from all forms should be submitted with the AJAX request.

However, even with Mojarra 2.0.3 this doesn't happen. Despite of contents of the execute attribute (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?

Community
  • 1
  • 1
Tuukka Mustonen
  • 4,722
  • 9
  • 49
  • 79
1

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.

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.

dave
  • 11
  • 1
0

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.

Vítor E. Silva Souza
  • 1,575
  • 1
  • 18
  • 23