i have a huge jsf-page with an underlying ViewScopeBean that contains a very large form (containing nearly 100 inputs) with many ajaxified input fields. for every input field, i only submit the current value and render nothing. so just a sample field in that form:
<h:selectBooleanCheckbox id="includeForeignCurrencies"
value="#{RatingManagerBean.formData.foreignCurrencies}"
action="#{RatingManagerBean.calculate}">
<f:ajax render="@none" execute="includeForeignCurrencies"/>
</h:selectBooleanCheckbox>
after the ajax post i inspect e.g. the developer tools in firebug and recognize that the submitted size of the post data is up to 2 kb. then i select the row, choose "copy post data" and pasted it into an editor:
every field of that form is submitted although i am only interested in the current changed field:
form-search=form-search
countryCode=AT
ratingType={"type":"COUNTRY"}
averageRating
minAmount
maxAmount
averageAmount
company
location
staffResponsible
staffResponsible2
requestDate
reminderDate
acutalCurrency
compareCurrencies
//70 other empty form-ids....
includeForeignCurrencies=on
javax.faces.ViewState=1825148886808299106:-354534052529224349
javax.faces.source=includeForeignCurrencies
javax.faces.partial.event=click
javax.faces.partial.execute=includeForeignCurrencies
javax.faces.behavior.event=valueChange
javax.faces.partial.ajax=true
is there a way to reduce the posted data like:
includeForeignCurrencies=on
javax.faces.ViewState=1825148886808299106:-354534052529224349
javax.faces.source=includeForeignCurrencies
javax.faces.partial.event=click
javax.faces.partial.execute=includeForeignCurrencies
javax.faces.behavior.event=valueChange
javax.faces.partial.ajax=true
or even just
includeForeignCurrencies=on
thanks in advance!
Workaround:
as a possible workaround i came up with disabling all inputs that did not trigger the post and re-enable them in ajax complete. post data size is now 200 B instead of 2000 B.
as i am not sure if this may cause any other issues, this is an update of the question, not an answer.
<h:selectBooleanCheckbox id="includeForeignCurrencies"
value="#{RatingManagerBean.formData.foreignCurrencies}"
action="#{RatingManagerBean.calculate}"
onclick="prepareAjaxPost(this)">
<f:ajax render="@none" execute="includeForeignCurrencies" onevent="ajaxPostComplete"/>
</h:selectBooleanCheckbox>
javascript/jQuery:
function prepareAjaxPost(source){
//keep already disabled inputs disabled
$("#form-search :input:not(:disabled)").filter(function() {
return !this.id.match(/javax.faces.ViewState/); //all inputs ignoring jsf- viewstate ones
}).each(function(){
var input = $(this);
var others = input.not(source);
others.attr("disabled", true);
others.addClass("blocked"); //some style that has no visual effect for users
});
}
function ajaxPostComplete(data) {
switch (data.status) {
case "success": {
$("#form-search :input.blocked").each(function(){
$(this).attr("disabled",false).removeClass("blocked");
});
break;
}
}
Start by reading the 'edit 2:' at the end
I know your question is about JSF 2.3, but out of curiosity, I wanted to see if it would be possible at all in plain JSF. And the good thing is that it seems possible for at least Mojarra 2.2.8 (did not have any other environments at hand quickly) by overriding a jsf.js function. And... if you want it to be 'conditional', so not on every input/button/..., also add a passthrough attribute.
I checked/debugged the sourcecode of the Mojarra jsf.js file and noticed it is only possible to strip/filter out fields after the full querystring is created instead of the PrimeFaces way where they prevent fields to be added 'upfront'. The function where this can be done is the getViewState and by overriding this, calling the original one and adding some logic before returning the result, it all seems to work. The downside is that it might filter out to much (see the comment at the end)
The js to add to your code (make sure it loaded is after jsf.js)
partialSubmit.js
And example of the usage is provided below. In this example the first and last input fields have
pt:partialSubmt="true"
added to the inputs (could not get it to work when added to the ajax tag). There are also two ajax enabledh:commandButtons
, one with and one without the partial submit. Using the browser developer tool you can see the differences when using thempartialSubmitDemo.xhtml
You can see some comments in the javascript code that it needs optimization but it is a good working start/beginning.
Edit:
pt:partialSubmit="true"
to the<h:form>
So using it form wide<o:form includeRequestParams="true">
and they are not stripped due to them not being in the 'viewState' key-value pairs of the form fields.Edit 2:
The great OmniFaces project will have this in the upcoming 3.0 release. A commit has been made by @BalusC that closed issue 394 that I created there as a result of this question. WITHIN 5 DAYS Using the
will default to a partialSubmit