Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0: Why does f:ajax send all the form fields and not only those marked with execute-attribute?

Tags:

java

jsf

jsf-2

Seems like I am having a bunch of JSF related questions these days... here it goes again: why does AJAX call declared with f:ajax post all the fields of the form and not only those declared with execute? This question was already asked in the Sun forums, but as they are now closed I cannot reply there. The thread there is a stub with no real answer to this.

What's the point of submitting all the form fields if I need to use only some of them?

like image 699
Tuukka Mustonen Avatar asked Oct 08 '10 11:10

Tuukka Mustonen


3 Answers

I just checked the JSF ticket that Tuuka had posted way back in Jan 2011. It said that this behavior (submitting all the form fields) is consistent with the JSF spec, and the issue was closed.

The JSF developers have posted a spec change notice that this should be modified in an upcoming spec. This had a date of Jan 31, 2013. https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1098

"f:ajax doesn't obey the 'execute' attribute but always sends all the fields in a form. Mojarra does, however, only process the listed fields as supposed. However, excess fields shouldn't be sent because it increases request size."

"Status: open Priority: major"

like image 162
klevi Avatar answered Nov 01 '22 22:11

klevi


This seems to be a bug in the jsf.js The getViewState function returns all the parameters (instead of filtering them), which are then sent to the server in the request string.

example: j_idt15=j_idt15&j_idt15%3Avalue1=4444&j_idt15%3Avalue2=555&j_idt15%3Avalue3=6664&javax.faces.ViewState=-6275268178907195611%3A5276476001199934151&javax.faces.source=j_idt15%3Avalue1&javax.faces.partial.event=blur&javax.faces.partial.execute=j_idt15%3Avalue1%20j_idt15%3Avalue1&javax.faces.partial.render=value1out&javax.faces.partial.ajax=true

Here you can see that the even though javax.faces.partial.execute is correctly specified as: j_idt15:value1, the request still contains all the values

like image 33
Rami Ayoub Avatar answered Nov 01 '22 21:11

Rami Ayoub


I am not 100% sure, but this might be a bug in Mojarra. See a similar question about the special @all keyword.

In short: Mojarra doesn't obey the list of forms entered for execute attribute of f:ajax but always submits only the enclosing form. The same probably applies to a more detailed field level as well - Mojarra does not obey the execute attribute when choosing what fields to submit, but simply sends them all. It does obey the execute attribute when processing the data in the server-side, however.

Can anyone test if the behavior differs from this with Apache Myfaces?

like image 26
Tuukka Mustonen Avatar answered Nov 01 '22 22:11

Tuukka Mustonen