如何防止JSF2注入隐藏的javax.faces.ViewState [英] How to prevent JSF2 injection of hidden javax.faces.ViewState

查看:710
本文介绍了如何防止JSF2注入隐藏的javax.faces.ViewState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁止Mojarra注入隐藏在<form>中的javax.faces.ViewState?我有一个搜索<form method='GET'>,它在第一次加载页面时有效(因为正确地重新初始化了我的视图范围的bean).但是在页面上的AJAX分页之后(通过PrimeFaces网格),Mojarra(或PrimeFaces?)将隐藏的javax.faces.ViewState注入到我的表单中.现在,当我提交表单时,由于javax.faces.ViewState输入,它不会重新启动我的view-scope bean.

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.

这里的问题是:我希望我的搜索bean初始化并将结果显示给用户,但是当传递ViewScope参数时,既没有初始化此bean,也没有显示相关页面.它只是保留在上一页.

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.

推荐答案

不是Mojarra在做,而是PrimeFaces在做.尝试用<f:ajax>调用<h:commandButton>,您将看到它仅更新按钮最初所在的表单的视图状态.

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.

您可能需要向PrimeFaces员工报告他们应该在问题 Ajax更新不会触摸任何具有method="get"和/或没有<input type="hidden" name="formId" value="formId"><form>元素.

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">.

在他们解决该问题之前,最好的选择是在提交纯HTML表单时删除该元素.

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'))">

这篇关于如何防止JSF2注入隐藏的javax.faces.ViewState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆