Hi,
Sorry for a question that I should already know the answer to, but how do I go about deleting the selected row from the datatable? I would have assumed that I would need to get the index of the selected row, and then remove the data from the list by that index (myList.remove(index)). I can't seem to find out how to get the index of the selected row...
Thanks,
B
Delete the selected row from datatable
Anyone?
Because I have
I can do the following:
That might work if myList is an java.util.ArrayList. Does anyone know how I can get the selectedRowIndex?
Because I have
Code: Select all
<p:datatable selection="#{myFace.selectedRow}">
Code: Select all
public void onDeleteClicked(ActionEvent event)
{
if (selectedRow != null)
{
selectedRow = null;
myList.remove(selectedRow);
}
}
PrimeFaces-3.2, Glasfish 3.1, JSF 2.0, IDEA 11, Mojarra 2.0.3
- bumble.bee
- Posts: 723
- Joined: 29 Sep 2010, 21:39
- Location: United States
You might consider taking advantage of a method expression to pass the model object representing a row from the view to the server. It would look something like:
Code: Select all
<h:form>
<p:dataTable var="myEntity" value="#{myBean.entities}">
...
<p:column>
<p:commandLink ajax="true" action="#{myBean.removeEntity(myEntity)}" update="@form growl" process="@this">
<span title="Remove" class="ui-icon ui-icon-trash"/>
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
<p:growl/>
-
- Posts: 24
- Joined: 22 Oct 2010, 20:00
This works fine for me:
PS:#{item} is the datatable var.
Code: Select all
<p:column headerText="Options">
<p:rowEditor />
<p:commandLink
action="#{mBean.action}"
value=" " styleClass="ui-icon ui-icon-trash"
update="@this" ajax="true">
<f:setPropertyActionListener
target="#{tabelaOutrasDespesasMBeanForm.selectedItem}"
value="#{item}" />
</p:commandLink>
</p:column>
JSF2 - Primefaces-3.1.RC1
Hi guys,
Thank you very much for your replies. I do understand what you mean. But in my case I don't want a column specifically for deleting the row, but instead, have a footer with a delete button on it, that is enabled when a row is selected.
Example: http://www.primefaces.org/showcase/ui/d ... Single.jsf
Imagine the "View" button was actually a "Delete" button, and imagine that I want to pass in the rowIndex for that selected row, rather than the object that represents that row. The reason I want the rowIndex instead of the selectedRow is because I want to do the following:
I don't want to do what you have done in another thread bumble.bee (http://primefaces.prime.com.tr/forum/vi ... f=3&t=6176) whereby you access the database and delete a row from it with an entityManager. I am not working with entities in my scenario.
Again thank you very much for your replies
Thank you very much for your replies. I do understand what you mean. But in my case I don't want a column specifically for deleting the row, but instead, have a footer with a delete button on it, that is enabled when a row is selected.
Example: http://www.primefaces.org/showcase/ui/d ... Single.jsf
Imagine the "View" button was actually a "Delete" button, and imagine that I want to pass in the rowIndex for that selected row, rather than the object that represents that row. The reason I want the rowIndex instead of the selectedRow is because I want to do the following:
Code: Select all
public void onDeleteClicked(ActionEvent event)
{
// myList is the list that the datatable uses to render the rows on the page.
myList.remove(rowIndex);
}
Again thank you very much for your replies
PrimeFaces-3.2, Glasfish 3.1, JSF 2.0, IDEA 11, Mojarra 2.0.3
-
- Posts: 24
- Joined: 22 Oct 2010, 20:00
The problem seems to be how to send the right index during the row selection event.
The only solution I came up with is involving an ugly "work around" (too ugly to be posted here), and I believe that others can present a better solution.
The only solution I came up with is involving an ugly "work around" (too ugly to be posted here), and I believe that others can present a better solution.
JSF2 - Primefaces-3.1.RC1
- bumble.bee
- Posts: 723
- Joined: 29 Sep 2010, 21:39
- Location: United States
You might try taking a look at the source:
http://code.google.com/p/primefaces/sou ... elper.java
It looks like the server pulls out the selected row index using the request param name: table clientId + "_selection".
You might also try "binding" a datatable component.
http://code.google.com/p/primefaces/sou ... elper.java
It looks like the server pulls out the selected row index using the request param name: table clientId + "_selection".
You might also try "binding" a datatable component.
-
- Posts: 30
- Joined: 23 May 2011, 22:03
@daniel.camargo
How did you get that to work? is there some weird stack order that fires in just the right way to get consistent results? for some reason, I can't get the setPropertyActionListener to do its job even though I see it implemented in various primefaces components...
Hope this reaches you. Thanks for any info you can provide.
How did you get that to work? is there some weird stack order that fires in just the right way to get consistent results? for some reason, I can't get the setPropertyActionListener to do its job even though I see it implemented in various primefaces components...
Hope this reaches you. Thanks for any info you can provide.
Primefaces 4.0 // Majorra 2.1.24 // Tomcat 7.x
-
- Information
-
Who is online
Users browsing this forum: No registered users and 69 guests