简体   繁体   English

如何通过悬停/鼠标悬停事件对 PrimeFaces 数据表的 select 行

[英]How to select row of PrimeFaces dataTable via hover/mouseOver event

I have a dataTable, to which I want to add column with a Delete button for each row.我有一个数据表,我想为每一行添加一个带有删除按钮的列。 My issue is, that I don't know how to change the currentItem member variable of my bean class, before the delete method is called in the command button's actionListener.我的问题是,在命令按钮的 actionListener 中调用 delete 方法之前,我不知道如何更改我的 bean class 的 currentItem 成员变量。

I've tried adding a setPropertyActionListener tag:我试过添加一个 setPropertyActionListener 标签:

        <p:column>
            <p:commandButton value="Delete" actionListener="#{itemBean.deleteItem}" process="@this"
                             update="table StartButtonForm">
                <f:setPropertyActionListener value="#{item}" target="#{itemBean.currentItem}"/>
            </p:commandButton>
        </p:column>

but the value only gets changed after itemBean.deleteItem is called in the button's actionListener, so currentItem is not updated in time and the wrong item gets deleted.但是只有在按钮的actionListener中调用了itemBean.deleteItem后才会改变值,所以currentItem没有及时更新,错误的item被删除了。

Does anyone know how to change the currentItem whenever you hover with your mouse over a row?有谁知道当您将鼠标悬停在一行上时如何更改 currentItem?

Here is the whole table in my xhtml file in case it's important:这是我的 xhtml 文件中的整个表格,以防它很重要:

    <p:dataTable id="table" var="item" value="#{itemBean.unrankedItems}" selection="#{itemBean.currentItem}"
                 selectionMode="single" rowKey="#{item.name}" rowSelectMode="add">
        <p:ajax event="rowSelect" listener="#{itemBean.onRowSelect}"/>
        <p:column>
            <h:outputText value="#{item.name}"/>
        </p:column>
        <p:column>
            <p:commandButton value="Delete" actionListener="#{itemBean.deleteItem}" process="@this"
                             update="table StartButtonForm">
                <f:setPropertyActionListener value="#{item}" target="#{itemBean.currentItem}"/>
            </p:commandButton>
        </p:column>
    </p:dataTable>

There is an exact Showcase example for your scenario with a Delete button in each row.您的场景有一个确切的展示示例,每行都有一个删除按钮。

See: https://www.primefaces.org/showcase/ui/data/datatable/crud.xhtml参见: https://www.primefaces.org/showcase/ui/data/datatable/crud.xhtml

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

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