【问题标题】:Primefaces retrieve DataList or DataGrid valuePrimefaces 检索 DataList 或 DataGrid 值
【发布时间】:2023-04-04 00:34:02
【问题描述】:

我有以下数据列表,它显示带有分页的图像,一次显示一个图像。当我单击我的 p:commandButton 时,我希望能够知道/检索正在显示的图像,以便我可以在我的 actionListener 方法(bookmarkletBean.update)中访问它。这里有什么想法吗?

  <p:dataList value="#{bookmarkletBean.imageURLs}" var="img"  
                    paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" paginatorPosition="bottom">  
                    <p:column>  
                        <p:graphicImage value="#{img}" width="200" height="110"/> 
                    </p:column>  
                </p:dataList>  

<p:commandButton styleClass="form-btn1" value="#{bundle['save.button.TEXT']}"   
                        actionListener="#{bookmarkletBean.update}"  oncomplete="bookmarkletAddedDlg.show()" />

【问题讨论】:

  • 那么显然格式化帖子以便更容易和增强阅读不再值得了吗?

标签: primefaces


【解决方案1】:

不可能,因为p:dataListp:dataGrid 都没有selection 属性可以附加到您的p:commandButton 所属的支持bean。

因此,我建议使用具有 selection 属性的p:dataTable,一旦单击该按钮,您现在将选择哪一行(图像)。

<p:dataTable value="#{bookmarkletBean.imageURLs}" var="img" 
             selection"#{bookmarkletBean.selectedImage}"
             paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
             paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks}     {NextPageLink} {LastPageLink}" paginatorPosition="bottom">  
                    <p:column>  
                        <p:graphicImage value="#{img}" width="200" height="110"/> 
                    </p:column>  
</p:dataTable>  

<p:commandButton styleClass="form-btn1" value="#{bundle['save.button.TEXT']}"   
                        actionListener="#{bookmarkletBean.update}"  oncomplete="bookmarkletAddedDlg.show()" />

【讨论】:

  • 感谢您的回复和帮助。选择没有将当前行映射到我的 bean。我认为 selection 属性是在有选择事件(单击、双击..等)时使用的。我只是使用分页转到集合中的下一个图像。我让它工作的唯一方法是我在下面的帖子中概述的方式。有任何想法吗?抱歉之前的格式。
【解决方案2】:

一个可能的解决方案是如下安排它,通过链接选择想要的图像,然后 actionListener 进程的选择

 <p:dataTable value="#{bookmarkletBean.imageURLs}" var="img"
              paginator="true" rows="1" effectSpeed="fast" pageLinks="4"
              paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
              paginatorPosition="bottom">  
              <p:column>  
                    <p:graphicImage value="#{img}" width="200" height="110"/> 
                        <p:commandLink> 
                            <f:setPropertyActionListener value="#{img}" target="#{bookmarkletBean.selectedImage}"/>
                                select image
                        </p:commandLink>
              </p:column>  
</p:dataTable>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-30
    • 2012-10-03
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    相关资源
    最近更新 更多