can i use FixViewState.js from omnifaces with richfaces' a4j:ajax (RF4+JSF2.2/mojarra)

北城以北 提交于 2019-12-23 02:01:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!