部分渲染仅适用于@form? [英] Partial Rendering will only work with @form?

查看:77
本文介绍了部分渲染仅适用于@form?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的情况,在更新属性中使用@parent甚至显式id都不起作用.但是@form可以正常工作.

I have a strange situation where using @parent, or even explicit id-s dont work in the update attribute. But @form works fine.

我做了一个非常简单的测试用例,其中包括一个简单的网格,其行为如下:

I've made a very simple test case, that includes a simple grid whose behaviour is like this :

  1. 网格中的每个记录都有一个修改按钮
  2. 单击修改"按钮后,它将修改服务器数据,并且该按钮将消失,因为只有在未修改记录的情况下才会呈现该按钮.

修改按钮是这样的:

<!-- this works, since it's using @form in the update attribute -->
<p:column>
    <p:commandLink
        value="modify record" 
        process="@this" 
        action="#{testUserBean.modifyRecord(user)}"
        update="@form"
        rendered="#{not testUserBean.isRecordModified(user)}" />
</p:column>

请注意,update属性使用@form使其起作用:单击修改按钮时,它会重新呈现并消失.

Notice that the update attribute makes use of @form which makes it work: when the modify button is clicked, it rerenders and disappears.

用@this或@parent或网格ID代替它,则它将不起作用.对我来说,在update属性中使用网格ID是非常合乎逻辑的,因为我想在单击按钮后刷新网格. 我尝试使用rowIndexVar="rowIndex"myGridId:#{rowIndex}:link,但仍然无法正常工作.

Substitute it with @this or @parent or the id of the grid, then it will NOT work. For me it's very logical to use the id of the grid in the update attribute, since i would like to refresh the grid after clicking on the buttton. I tried making use of rowIndexVar="rowIndex" and myGridId:#{rowIndex}:link, but still aint working.

<!-- this does not work -->
<p:column>
    <p:commandLink id="link"
        value="modify record" 
        process="@this" 
        action="#{testUserBean.modifyRecord(user)}"
        update="tblUser"
        rendered="#{not testUserBean.isRecordModified(user)}" />
</p:column>

以下是此简单示例的资源:

Here are the resources for this simple example :

  1. xhtml文件
  2. JSF Bean文件
  3. 用户POJO bean
  1. The xhtml file
  2. The JSF Bean file
  3. The user POJO bean

我正在使用tomcat 7,这些是我的依赖项:

Im using tomcat 7, and these are my dependencies :

<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.0.4-b09</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.0.4-b09</version>
    <scope>compile</scope>
</dependency>

还试用了primefaces 3.0.M1,但它也具有相同的行为.

Tried out primefaces 3.0.M1 also, but it got the same behavior also.

请分享您的想法.这是错误还是我做错了什么?

Please share your ideas. Is this a bug or i did something wrong ?

更新

你好

我刚刚完成了一些测试,但是所有测试仍然失败.

I've just finished some testing, but all still fails.

测试1(使用update=":gridRPBDetails"):

Test 1 (making use of update=":gridRPBDetails") :

JSF文件:

<p:commandLink id="undoLink" value="Undo" process="@this"
    action="#{tInputBean.actionUndoRemoveRecord(rpbDetail)}"
    update=":gridRPBDetails"
    rendered="#{tInputBean.isRemoveRecord(rpbDetail)}"
    title="Batalkan buang data" />

生成的xhtml:

<a title="Batalkan buang data" onclick="PrimeFaces.ajax.AjaxRequest('/cashbank/faces/TInput.xhtml',
{formId:'j_idt38',async:false,global:true,source:'gridRPBDetails:0:undoLink',
process:'gridRPBDetails:0:undoLink',update:':gridRPBDetails'});" 
href="javascript:void(0);" id="gridRPBDetails:0:undoLink">Undo</a>

测试2(使用update=":gridRPBDetails:#{rowIndex}:undoLink"):

Test 2 (making use of update=":gridRPBDetails:#{rowIndex}:undoLink") :

JSF文件:

<p:commandLink id="undoLink" value="Undo" process="@this"
    action="#{tInputBean.actionUndoRemoveRecord(rpbDetail)}"
    update=":gridRPBDetails:#{rowIndex}:undoLink"
    rendered="#{tInputBean.isRemoveRecord(rpbDetail)}"
    title="Batalkan buang data" />

生成的xhtml:

<a title="Batalkan buang data" onclick="PrimeFaces.ajax.AjaxRequest('/cashbank/faces/TInput.xhtml',
{formId:'j_idt38',async:false,global:true,source:'gridRPBDetails:0:undoLink',
process:'gridRPBDetails:0:undoLink',update:':gridRPBDetails:0:undoLink'});" 
href="javascript:void(0);" id="gridRPBDetails:0:undoLink">Undo</a>

在单击撤消"按钮后,这两项测试仍然失败,无法刷新网格的记录,甚至无法刷新网格本身.

Both tests still fail in terms of clicking the undo button cannot refresh the record of the grid, or even the grid itself.

更新

我刚刚使用:

<p:commandLink
    value="modify record" 
    process="@this" 
    action="#{testUserBean.modifyRecord(user)}"
    update=":mainForm:tblUser"
    rendered="#{not testUserBean.isRecordModified(user)}" />

注意,我使用了:mainForm:tblUser,但是我尝试了其他选项,但仍然失败了:

Notice i used the :mainForm:tblUser, and i've tried the other options and still failed :

  1. :mainForm:tblUser:
  2. :tblUser(当我不定义表单名称时)
  3. :mainForm:tblUser:#{rowIndex}:linkId

但是我注意到的一件事是,无论我选择了什么更新,更新总是以 tblUser:0

But 1 thing i notice is,nNo matter what i choosed for the update, the update always ends up as tblUser:0

<a onclick="PrimeFaces.ajax.AjaxRequest('/cashbank/faces/test.xhtml',
{formId:'mainForm',async:false,global:true,source:'tblUser:0:j_idt33',
  process:'tblUser:0:j_idt33',
  update:'tblUser:0'
});" href="javascript:void(0);" id="tblUser:0:j_idt33">modify record</a>

我尝试使用Firebug即时修改 tblUser:0 tblUser ,网格上的部分渲染工作正常.

I tried modifying tblUser:0 on the fly using firebug to just tblUser, the partial rendering on the grid works fine.

在开始尝试从网格记录内部更新网格时,我开始认为这是一个错误.

Im beginning to think that this is a bug when trying to update a grid from inside a grid record.

推荐答案

已在此处.

这是答案中的引言:

这更像是一个mojarra问题,它可以很好地与myfaces配合使用 没有包装.解决方法是放一个包装纸.

This is more like a mojarra issue, it should work fine with myfaces without a wrapper. Workaround is to put a wrapper.

  Code:
    <h:form id="frm">
       <p:outputPanel id="wrapper">
           <p:dataTable id="tbl">
           //...
               <p:commandButton update=":frm:wrapper" />
           //...
           <p:dataTable>
       <p:outputPanel>
    </h:form>

对不起,晚更新!

这篇关于部分渲染仅适用于@form?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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