如何重新解析页面的一部分,形式JSF 2.0? [英] How to rerender part of page with form in JSF 2.0?

查看:208
本文介绍了如何重新解析页面的一部分,形式JSF 2.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们正试图从JSF 1.2移动到JSF 2.0,我们所面临的问题之一是,它是不可能重新呈现包含窗体页的一部分。像这种(重新呈现 outerDiv 或形成自己的):

Currently we're trying to move to JSF 2.0 from JSF 1.2 and one of the problem we've faced is that it's impossible to rerender part of the page that contains form. Like this (rerender outerDiv or forms themselves):

<h:panelGroup id="outerDiv">
    <h:form id="form1">...</h:form>
    <h:form id="form2">...</h:form>
</h:panelGroup>

我的意思是,如果我更新 outerDiv 一切都在更新,但形式(或形式)本身变得破碎和行为异常,至少Ajax调用要么不工作时,第一次触发或代替调用一些Bean的方法,他们创建一个bean的新实例,什么也不做(无论是与销毁previous与每一个电话,或只是创造上的第一次调用新的,然后什么也不做)。 innerDiv1 和 innerDiv2 )来解决>

I mean that if i update outerDiv everything is updated but the form (or forms) itself becomes broken and behaves strangely, at least ajax calls either don't work when first time triggered or instead of calling some bean's method they create new instance of that bean and do nothing (either with destroying previous with every call or just creating new one on first call and then do nothing). The problem can be solved by rerendering only components inside form, like this (update innerDiv1 and innerDiv2):

<h:panelGroup id="outerDiv">
   <h:form id="form1">
       <h:panelGroup id="innerDiv1">...</h:panelGroup>
   </h:form>
   <h:form id="form2">
       <h:panelGroup id="innerDiv2">...</h:panelGroup>
   </h:form>
</h:panelGroup>

但我们有很多,我们有一些页面 UI地方:包括,它是不是很方便查看该页面内更新某些组件存在。此外,我们将不得不修改所有这些网页,因为其中许多人没有共同的包装DIV中的形式,并分别更新每个组件将是非常麻烦而且容易出错。
那么,有可能使JSF 2.0正确地更新页面的1-ST方法的一部分,就像是在JSF 1.2?

but we have a lot of places where we include some page with ui:include and it's not very convenient to look inside that page and update certain components there. Besides we'll have to modify all these pages as many of them don't have common wrapper div inside forms and update each component separately will be very cumbersome and error prone.
So, is it possible to make JSF 2.0 correctly update part of page with 1-st approach like it was in JSF 1.2?

编辑:它看起来像问题的形式呈现是RichFaces的4.2问题,因为我使用 A4J:AJAX (的 A4J接班人:支持这是基于丰富:的commandButton 。当我取代他们与本地JSF的 F:AJAX 的形式似乎是正确刷新。但问题外层div还是实际

it looks like the issue with form rendering is richfaces 4.2 issue as i use a4j:ajax (successor of a4j:support that was used with richfaces 3.3.3) and custom buttons based on rich:commandButton. When i substituted them with native jsf's f:ajax forms seems to be refreshed correctly. But issue with outer div is still actual

推荐答案

这是关系到部分国家储蓄。如果AJAX的更新组件中又包含一个形式,它的一个孩子,那么它的视图状态会迷路。该表格​​内的每个第一次Ajax请求将失败,因为不存在视图状态。但如果Ajax请求重新呈现的形式本身,那么它会工作。

This is related to partial state saving. If you ajax-update a component which in turn contains a form as one of its children, then its view state will get lost. Every 1st ajax request inside that form will fail because there's no view state. But if that ajax request is re-rendering the form itself, then it will work.

要解决这个问题,你需要为明确提供其他形式的AJAX(S)的ID 渲染 / 更新属性旁边的 outerDiv 每当它从调用的另一个的形式。

To fix this, you need to explicitly include the ID of the other form(s) in ajax render/update attribute next to outerDiv whenever it's invoked from another form.

例如。

<h:form>
    <h:commandButton value="Update other forms">
        <f:ajax render="outerDiv form1 form2" />
    </h:commandButton>
</h:form>
<h:panelGroup id="outerDiv">
    <h:form id="form1">...</h:form>
    <h:form id="form2">...</h:form>
</h:panelGroup>

没有,这会不会导致与重复组件的Ajax响应。它只是将触发JSF为prepare和保存这些其他形式的状态。

No, this will not result in an ajax response with duplicate components. It will just trigger JSF to prepare and save the state of those other forms.

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

这篇关于如何重新解析页面的一部分,形式JSF 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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