简体   繁体   English

带有链接的jsf / primefaces dataTable; 打开/显示错误的一个

[英]jsf/primefaces dataTable with links; wrong one opened/displayed

I have a primefaces dataTable with several URLs as data. 我有一个素数表dataTable,其中有几个URL作为数据。 There is one URL per line. 每行只有一个URL。 A line has a button. 一行有一个按钮。 If you click it, a dialog is opened, containing a iframe with the website of the corresponding URL. 如果单击它,则会打开一个对话框,其中包含带有相应URL网站的iframe。

This is the (shortened) xhtml: 这是(缩短的)xhtml:

<p:dataTable id="transResult" rendered="#{not empty urlList}"
             var="aUrl"
             value="#{urlList}">
   <p:column ...></p:column>
   ...
   <p:column>
       <p:commandButton id="urlBtn" value="#{aUrl}"     
                        onclick="PF('showURL').show();"/>

       <p:dialog id="urlDialog" widgetVar="showURL">
           <h:outputLabel value="URL:&#160;#{aUrl}"/>
           <iframe src="#{aUrl}"/> 
       </p:dialog>
   </p:column>
</p:dataTable>

The table with the buttons is displayed correctly: 带按钮的表正确显示:

|url1|
|url2|
...

If I have a look at the hidden dialogs with firebug, the URLs are put correctly! 如果我看一下带有Firebug的隐藏对话框,则可以正确放置URL! Also the id's are generated corrctly: ID也会正确生成:

transResult:0:urlDialog
transResult:1:urlDialog
...

Problem: But when I click on a button, always the dialog with the last URL is openend. 问题:但是,当我单击按钮时,带有最后一个 URL的对话框始终是openend。

Any idea why this goes wrong? 知道为什么会出错吗?

I found a solution that seems to work. 我找到了似乎可行的解决方案。 The base is to have different widgetVar. 基本是要具有不同的widgetVar。

<p:dataTable id="transResult" rendered="#{not empty urlList}"
         var="data"
         value="#{urlList}">
    <p:column ...></p:column>
    ...
    <p:column>
        <p:commandButton id="urlBtn" value="#{aUrl}"     
                         onclick="PF('showURL#{data.id}').show();"/>

       <p:dialog id="urlDialog" widgetVar="showURL#{data.id}">
           <h:outputLabel value="URL:&#160;#{data.aUrl}"/>
           <iframe src="#{data.aUrl}"/> 
       </p:dialog>
   </p:column>
</p:dataTable>

So we have an ID per row which is also added to the widgetVar to make them different. 因此,我们每行都有一个ID,该ID也已添加到widgetVar中以使其与众不同。

Note that with this solution everything is calculated when the table is created. 请注意,使用此解决方案时,将在创建表时计算所有内容。 So there is nothing "dynamic". 因此,没有任何“动态的”。 But for my needs this is no problem. 但是对于我的需求,这没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM