This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Delete/edit a row in JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Delete/edit a row in JSF" Watch "Delete/edit a row in JSF" New topic
Author

Delete/edit a row in JSF

Anil Gorthy
Greenhorn

Joined: Oct 30, 2008
Posts: 13
Hi:

My application is a standard MVC app which uses Apache Trinidad as its front-end. A few weeks backs I posted a question about displaying buttons in a table based on a if-else condition and I was told to use DataModel and I have used it: Display_if_else_condition

Now, when I am trying to delete/edit a row, I am unable to capture the selected row in the backing bean. When I am trying to read the table using getRowData() it is returning null. Here is the code in my JSPX file:

And in the backing bean (this code is from Trinidad's dev page: Trinidad_Tables):

I need to capture the selected row - which in my application is a DTO and send it to the DAO for deletion. Can you please let me know what I am doing incorrectly here that I cannot capture the selected row? Thank you in advance for your time!

FYI, I cross-posted this question on Sun's JSF Forums as well: Cross-post_Sun_JSF_Forum

Best,
Anil.
Anil Gorthy
Greenhorn

Joined: Oct 30, 2008
Posts: 13
Thank you all for attempting to provide a solution. The reason I could only see null whenever a row was selected is due to my backing bean not being in a session scope. After changing it to session from request, I was able to capture the selected row.

The relevant part in my faces-config.xml:There was also one other discussion on MyFaces - Users mailing list that was very helpful and which clarified that I should use session scope was:
[url=http://www.nabble.com/Table's-data-not-displayed-upon-setting-"binding"-attribute-with-tr:table-td2470023.html]MyFaces-Table-Binding[/url]

Just as an FYI, as mentioned by this user, I too have used both value="#{adminBean.names}" and binding="#{adminBean.table}".

What I have not been able to accomplish was refreshing the table whenever the delete operation is completed. Since this table is displayed only when a user selects an item in the listbox, they currently will have to select a different item in the listbox for this table to refresh. Not a pretty UI experience but I will get to it.

I have completed the Delete row part and the Edit row is pending however, retrieving the selected rows' values was the critical piece.
Rajneesh Kumar Rajput
Ranch Hand

Joined: Feb 25, 2009
Posts: 39
Hi Anil,
Changing scope to the session, was not the fix it was just an alternate.
So, you have assumed that for request scope bean a selected row data cannot be fetched.
Anil Gorthy
Greenhorn

Joined: Oct 30, 2008
Posts: 13
Hi Rajneesh,

When that bean was placed in the session, I was able to retrieve the values of the selected row however, as you have rightly mentioned, that is a workaround. So, I will go back and convert this bean to request scope.

Thank you!

Best,
Anil.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Delete/edit a row in JSF
 
Similar Threads
table and partial triggers
selectBooleanCheckbox
ValueChangeEvent fires for every datatable changed value, cannot reset.
Problem with Trinidad Nested Table (depth 3)
tr:commandButton actionListener not invoking managed bean method