0

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.

I've tried adding a setPropertyActionListener tag:

        <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.

Does anyone know how to change the currentItem whenever you hover with your mouse over a row?

Here is the whole table in my xhtml file in case it's important:

    <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>

1 Answers1

0

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

Melloware
  • 10,435
  • 2
  • 32
  • 62