JSF和p:阿贾克斯内部号码:dataTable的内部UI:重复号码、阿贾克斯、JSF、dataTable

2023-09-10 15:48:25 作者:狂饮风中血

我熟悉的RichFaces的,但相对较新的Primefaces并试图实现一个简单的 H:graphicImage的 A P的内侧:dataTable的(另外在 UI:重复)。这是 p的后续问题:阿贾克斯内H:graphicImage的。

I'm familiar with RichFaces, but relatively new to Primefaces and trying to implement a simple h:graphicImage inside a p:dataTable (additionally inside a ui:repeat). This is the subsequent question of p:ajax inside h:graphicImage.

我会被拆分为以下 XHTML - code直接评论的行为:

I will split the following xhtml-code to directly comment the behavior:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xml:lang="en" lang="en">
  <h:head id="head">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Test</title>
  </h:head>
    <h:body id="body">
      <f:view contentType="text/html">

现在第一个 H:形式如下,其中包含一个 H:的outputText H:graphicImage的。通过点击图像上的bean的方法被调用和柜台的正确更新。

Now the first h:form follows which contains a h:outputText and a h:graphicImage. By clicking on the image the bean method is called and the counter is correctly updated.

<h:form id="f1">
  <h:outputText id="counter" value="#{clientBean.counter}" />
  <h:graphicImage url="/images/circle-ok.png">
    <p:ajax event="click" update="counter" process="@this"
            listener="#{clientBean.tag}"/>
  </h:graphicImage> 
</h:form><hr/>

在第二个 H:形式按钮是 P的内侧:dataTable中。如果我点击图片,bean方法被称为计数器进行更新。 (注意在firt我试图更新=计数器没有成功)

In the second h:form the button is inside a p:dataTable. If I click on the image, the bean method is called the counter is updated. (Note At firt I've tried to update="counter" without success)

<h:form id="f2">
  <p:dataTable var="var" value="#{clientBean.vf}">
    <p:column> 
      <f:facet name="header">Tag</f:facet>
      <h:graphicImage url="/images/circle-ok.png">
        <p:ajax event="click" update="f1:counter" process="@this"
                listener="#{clientBean.tag}" />
      </h:graphicImage>
    </p:column>
  </p:dataTable>
</h:form><hr/>

内的图像 UI:重复更新的柜台的预期:

<ui:repeat var="var1" value="#{clientBean.list}">   
  <h:form id="f3">
    <h:graphicImage url="/images/circle-ok.png">
  <p:ajax event="click" update="f1:counter" process="@this"
              listener="#{clientBean.tag}" />
    </h:graphicImage> 

现在让前来号码:dataTable中 UI:重复。有了这块$ C $的C中的bean的方法的不可以名为:

Now lets come to the p:dataTable inside a ui:repeat. With this piece of code the bean method is not called:

    <p:dataTable var="var2" value="#{var1.list}">
      <p:column>  
        <f:facet name="header">Tag</f:facet>
        <h:graphicImage url="/images/circle-ok.png">
         <p:ajax event="click" update="f1:counter" process="@this"
                 listener="#{clientBean.tag}" />
        </h:graphicImage> 
      </p:column>
    </p:dataTable>
   </h:form>
 </ui:repeat>
</f:view></h:body></html>

在这种情况下,我得到的&LT;部分响应&GT;&LT;修改&GT;&LT;更新ID =F1:计数器&GT; ... ,但bean方法不叫(内部是标记()法的柜台的未更新)。这是用一个调试测试。 我读了 unable要使用&lt;号码:AJAX&GT;我primeface的数据表 但我有同样的behaivour与 primefaces-3.0.M3.jar primefaces-2.2.1.jar

In this case I get the <partial-response><changes><update id="f1:counter">..., but the bean method is not called (an inside it's tag()method the counter not updated). This is tested with a debug. I've read unable to use <p:ajax> on my primeface's datatable but I have the same behaivour with primefaces-3.0.M3.jar and primefaces-2.2.1.jar.

推荐答案

我曾经有过类似的问题。我可能是偏执狂,但我的即时通讯pression是迭代组件 UIData 在JSF2和 UIRepeat 被窃听。特别是,它们不会处理组件的状态正常它们嵌套时。我已经修补 UIRepeat 我和它的作品对我有任何级别的嵌套。我知道迭代分量从战斧正常工作为好。

I used to have a similar issue. I might be paranoid but my impression is the iterative component UIData and UIRepeat in JSF2 are bugged. In particular they won't handle component state properly when they are nested. I have patched UIRepeat myself and it works for me with any level of nesting. I know iterative component from tomahawk works correctly as well.

在特定的情况下,相当简单的解决方法可以帮助,因为你想的一样的行为,无论它的形象被点击。创建一个 H:commandLink 说,在形式与F1里面适当的AJAX元素和ID如更新计数器。把它藏起来。添加onclick属性您graphicImage的值为 jsf.ajax.request(F1:更新计数器,事件,{渲染:F1:计数器,执行=@这个})。您可能需要更换先用的document.getElementById参数(F1:更新计数器),我不知道。这个JavaScript API调用应该是相当于点击隐藏的commandLink。或者你可以尝试跳过commandLink并通过graphicImage的ID / DOM节点从f1来代替。

In your particular case a reasonably simple workaround could help since you want the same behavior regardless of which image is clicked. Create a h:commandLink say in form f1 with proper ajax element inside and id like 'update-counter'. Hide it. Add onclick attribute to your graphicImage with value jsf.ajax.request("f1:update-counter", event, {render: "f1:counter", execute="@this"}). You may need to replace the first argument with document.getElementById("f1:update-counter"), I'm not sure. This javascript api call should be equivalent to clicking the hidden commandLink. Alternatively you may try to skip the commandLink and pass graphicImage id/DOM node from f1 instead.

我曾经与 F做到这一点:阿贾克斯,但也许会为号码:AJAX 为好。

I used to do this with f:ajax, but maybe will work for p:ajax as well.