问题
I use the great omnifaces 1.7 workaround FixViewState in order to fix the following issue: viewstate and ViewScope gets lost on ajax render="@form". The workaround seems to work fine with f:ajax but not with a4j:ajax (richfaces).
Is the fix supposed to work with richfaces out-of-the-box? (richfaces version is 4.3.5)
maybe related issue logged by a4j:log:
error[15:09:31.667]: [status=200] During update: javax.faces.ViewState not found
Thanks!
回答1:
Tl;dnr: Richfaces-4.x is broken with JSF-2.2
Long version:
With regard to information from comments and from personal experience: this is a known bug with Richfaces-4.x in conjunction with Mojarra-2.2.x. See RF-13317 for the details.
The gist is that JSF-2.2 changed to spec for the ViewState
hidden input field and RichFaces hasn't kept up (it targets JSF-2.1, so that's fine). It still renders a JSF-2.1 viewstate id that confuses the Javascript included in Mojarra-2.2.x in that it now tries to find an element that has the JSF-2.1 viewstate id, but finds none. This makes every ajax call with RichFaces nominally fail, albeit in a non-destructive manner.
Personally, I use a rather ugly trick to make the above pass:
<o:onloadScript>
jQuery('#viewStateContainer').html('<span id="javax.faces.ViewState"></span>');
</o:onloadScript>
<span id="viewStateContainer" style="display:none;"></span>
This provides RichFaces with a fake element to put the viewstate into (destroying it in the process, so it needs to be re-created by onloadScript
).
This seems to solve my problems, but is rather confusing. So feel free to comment/ask about that.
回答2:
Sorry, I don't have enough reputation to comment on the chosen answer, but this seems to have been fixed since Richfaces 4.5.0 (see backporting issue).
来源:https://stackoverflow.com/questions/21726718/can-i-use-fixviewstate-js-from-omnifaces-with-richfaces-a4jajax-rf4jsf2-2-mo