我有一个巨大的 jsf 页面,其底层 ViewScopeBean 包含一个非常大的表单(包含近 100 个输入)和许多 ajaxified 输入字段。对于每个输入字段,我只提交当前值并且不呈现任何内容。所以只是该表单中的一个示例字段:
<h:selectBooleanCheckbox id="includeForeignCurrencies"
value="#{RatingManagerBean.formData.foreignCurrencies}"
action="#{RatingManagerBean.calculate}">
<f:ajax render="@none" execute="includeForeignCurrencies"/>
</h:selectBooleanCheckbox>
在 ajax 发布之后,我检查了例如 firebug 中的开发人员工具,并发现提交的发布数据的大小高达2 kb。然后我选择该行,选择“复制帖子数据”并将其粘贴到编辑器中:
尽管我只对当前更改的字段感兴趣,但该表单的每个字段都已提交:
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
有没有办法减少发布的数据,例如:
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
甚至只是
includeForeignCurrencies=on
提前致谢!
解决方法:
作为一种可能的解决方法,我想出了禁用所有未触发帖子的输入并在 ajax 完成中重新启用它们。发布数据大小现在是 200 B 而不是 2000 B。
因为我不确定这是否会导致任何其他问题,所以这是问题的更新,而不是答案。
<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;
}
}