阿贾克斯渲染其它形式导致其视图状态就完了,我怎么添加这个回来? [英] Rendering other form by ajax causes its view state to be lost, how do I add this back?

查看:153
本文介绍了阿贾克斯渲染其它形式导致其视图状态就完了,我怎么添加这个回来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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,然后我必须单击两次删除链接。这仅是一个例子。我没有这个真实的案例。我有多种形式的网页上,我不能只是添加所有的人都在一个单一的形式。

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.

我查了一下是什么问题,它是:

I checked what the problem is and it is:

  • 当你点击my_fake_ajax_link,在 mydiv refreshs使用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的错误给我。我不想刷新与自动div中

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.

推荐答案

这是JSF的自动包括 jsf.js 库,它负责处理Ajax响应一个已知的问题。另请参见 JSF规范问题790 。与此同时,随着JSF 2.0 / 2.1 / 2.2,你必须明确地指定其他的ID &LT; H:形式GT; 渲染 attribtue触发适量添加的视图状态的。

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 scheduled to be 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响应重复。

No, this does not cause any overhead or markup duplication in the ajax response.

  • <一个href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#AjaxRenderingOfContentWhichContainsAnotherForm">Communication在JSF 2.0 - 内容的Ajax渲染包含另一种形式

这篇关于阿贾克斯渲染其它形式导致其视图状态就完了,我怎么添加这个回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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