通过ajax渲染其他表单会导致其视图状态丢失,我该如何添加回来? [英] Rendering other form by ajax causes its view state to be lost, how do I add this back?
问题描述
我有
<h:form>
<h:commandLink action="#{my_fake_ajax_link}">
<h:outputText value="Link" />
<f:ajax render=":mydiv" />
</h:commandLink>
</h:form>
<h:panelGroup layout="block" id="mydiv">
<h:form>
<h:commandLink action="#{mybean.delete(0)}">
<h:outputText value="Here" />
<f:ajax render="@form" />
</h:commandLink>
</h:form>
</h:panelGroup>
当我在my_fake_ajax_link"上单击一次时,我必须在delete"链接上单击两次.这只是一个例子.我没有这个真实案例.我在一个页面上有多个表单,我不能将它们全部添加到一个表单中.
When I click once on "my_fake_ajax_link", then I have to click twice on "delete" link. This is only an example. I don't have this real case. I have multiple forms on a page and I can't just add all of them in a single form.
我检查了问题所在:
- 当您单击my_fake_ajax_link"时,
mydiv
会按照应有的 ajax 刷新. - 缺少 ajax 上刷新的表单的 ViewState.
- When you click on "my_fake_ajax_link", the
mydiv
refreshs with ajax as it should. - ViewState of the refreshed form on ajax is missing.
如何添加 ViewState?如何在不使用一种形式的情况下使其工作?对我来说,这看起来像是一个 JSF 错误.我不想用
How can I add the ViewState? How can I make it work without using only one form? This looks like an JSF bug to me. I don't want to refresh that div automatically with
jQuery("#mydiv").load(document.location.href);
但我会在最坏的情况下.
but I will in my worst case possible.
推荐答案
这是处理 ajax 响应的 JSF 自动包含的 jsf.js
库中的一个已知问题.另请参阅 JSF 规范问题 790,该问题已在即将推出的 JSF 2.3 中修复.同时,对于 JSF 2.0/2.1/2.2,您必须在 render
属性中明确指定其他
的 ID 以触发适当的添加视图状态.
This is a known problem in the auto-included jsf.js
library of JSF which handles ajax responses. See also JSF spec issue 790 which is fixed in the upcoming JSF 2.3. In the meanwhile, with JSF 2.0/2.1/2.2, you have to explicitly specify the ID of the other <h:form>
inside the render
attribtue to trigger proper addition of the view state.
<h:form>
<h:commandLink action="#{my_fake_ajax_link}">
<h:outputText value="Link" />
<f:ajax render=":mydiv :mydivForm" />
</h:commandLink>
</h:form>
<h:panelGroup layout="block" id="mydiv">
<h:form id="mydivForm">
<h:commandLink action="#{mybean.delete(0)}">
<h:outputText value="Here" />
<f:ajax render="@form" />
</h:commandLink>
</h:form>
</h:panelGroup>
不,这不会导致 ajax 响应中的任何开销或标记重复.或者,使用 OmniFaces fixviewstate.js
.
No, this does not cause any overhead or markup duplication in the ajax response. Alternatively, use OmniFaces fixviewstate.js
.
这篇关于通过ajax渲染其他表单会导致其视图状态丢失,我该如何添加回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!