Search code examples
ajaxjsf-2

Ajax submit with specific IDs in execute still submits entire form


As far as I understood, specifying IDs in the execute of an f:ajax tag should limit the fields which are posted to the server.

    <h:form>
        <h:inputText id="one" value="#{manageSettingsBean.testOne}"/>
        <h:inputText id="two" value="#{manageSettingsBean.testTwo}"/>

        <h:commandButton value="Multi test" action="#{maintainEntityAction.multi(manageSettingsBean.testOne, manageSettingsBean.testTwo)}">
            <f:ajax execute="@this one"/>
        </h:commandButton>
    </h:form>

In this case, I'd expect that only the first inputText would be submitted.

On examining the form data in Chrome's Network tab, however, I see

j_idt13=j_idt13&j_idt13%3Aone=One&j_idt13%3Atwo=Two&javax.faces.ViewState=-8624538035389330252%3A2147742525648157763&javax.faces.source=j_idt13%3Aj_idt14&javax.faces.partial.event=click&javax.faces.partial.execute=j_idt13%3Aj_idt14%20j_idt13%3Aone&javax.faces.behavior.event=action&javax.faces.partial.ajax=true

Which contains both components, with their default values (of "One" and "Two").

j_idt13:one=One
j_idt13:two=Two

The first component is specified in the javax.faces.partial.execute, so it is the only one that is updated, but both fields do seem to be submitted. I'm doing the partial submit as part of a large form to avoid posting up too much data, but the benefit would appear to be lost if the entire form is still being submitted?


Solution

  • The execute attribute has no relation to the submitting of fields or not. It influences their processing on the server. So in this regard your expectation is wrong and everything behaves as expected.

    PrimeFaces has introduced a partialSubmit for this that uses their process attribute (their counterpart of execute) to limit what is actually submitted.

    Based on this I created some code for another question <f:ajax render="@none" execute="@this"> and reducing submitted post data size in large form that makes this work on plain JSF as well and at the same time I submitted a feature request to OmniFaces to add the same functionality to the OmniFaces o:form. They improved it a little and added it to the upcoming release which you can already try as a 3.0-SNAPSHOT