How to prevent JSF2 injection of hidden javax.faces.ViewState

末鹿安然 提交于 2020-01-14 05:20:33

问题


How can I disallow Mojarra, injecting a javax.faces.ViewState hidden into my <form>s? I have a search <form method='GET'> which works first time my page is loaded (because my view-scoped bean is re-initialized correctly). But after an AJAX pagination in the page (over a PrimeFaces grid), Mojarra (or PrimeFaces?) injects a hidden javax.faces.ViewState into my form. Now when I submit the form it doesn't restart my view-scope bean because of javax.faces.ViewState input.

The issue here is: I want my search bean to initialize and show results to the user, but as ViewScope parameter is passed, neither this bean is initialized nor related page is shown. It just remains on the previous page.


回答1:


It's not Mojarra who's doing that, it's PrimeFaces who's doing that. Try invoking a <h:commandButton> with <f:ajax> and you'll see that it only updates the view state of the form where the button originally resides in.

You may want to report an issue to the PrimeFaces guys that they should during ajax updates not touch any <form> elements which have a method="get" and/or do not have an <input type="hidden" name="formId" value="formId">.

Until they get it fixed, your best bet is to remove the element on submit of the plain HTML form.

<form onsubmit="form.removeChild(document.getElementById('javax.faces.ViewState'))">


来源:https://stackoverflow.com/questions/10744054/how-to-prevent-jsf2-injection-of-hidden-javax-faces-viewstate

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