Using JSF H:DATATABLE
Hi,
I am new to using JSF and have started working on a project very recently. I am using a datatable which will have an edit and a delete link/button to edit/delete a particular row. This datatable also has a sort functionality using an actionListener, and this table list will be sorted based on the coulumne clicked.
Initially I had hardcoded the Edit and Delete columns in the datatable but the links were not binding to that particular row. so I put the Edit and Delete columns as String properties into the list that was going to be displayed on the table but still they are not binding to the particular row, Can anyone give a suggestion as to hoW I can do this.
# 2
Thank you.
I infact used the example listed in the website to create my JSF. But I don't see a solution to my problem in that example.
The Edit string and Delete string in the object is not binding to each row. For ex, if I have 4 objects say 1, 2, 3, 4 and initially when they are displayed on the screen, they are displayed in the order 3, 2, 1, 4. I sort it and the order is changed to 1, 2, 3, 4 but the edit and delete links does not change with the sort, the links in the first row is still bound to object 3, instead of to object 1. So if I click on the link "Edit" in the first row, it will bring up the row data for object 3 instead of object 1 after the sort..
Can you tell me what is happening or what I am doing wrong or what I can do to correct this?
# 7
This is what is happening:
1) reload data
2) invoke action
3) sort data
You have to rearrange your logic to:
1) invoke action
2) reload data
3) sort data
Or maybe (not recommended):
1) reload data
2) sort data
3) invoke action
Clicking at row don't set the object itself by the way, but only the row index. Keep this in mind.
# 8
I do not reload data whenever a sort action is invoked. The data is loaded once when the user comes into the screen, after that each time a sort action is invoked, it just uses the list in session and sorts the data.
Some more information on the application.
The list contains objects and the object has the following properties.
01-03-2007 -String(DateString)
Garnishments - String(Category)
JUnit added ... String(Text)
sprint3String(Userid)
A list of objects with the above said properties are retreived from the database. Within the object I add two more strings for each object
EditString
DeleteString
So my object now contains 4 properties which are populated from the database and 2 Strings, which are instantiated with default values in the object.
The user can sort the table by clicking on the column heading.
This list of objects is passed to web layer to be displayed in the jsp. When the user clicks on the "Edit" in each row, the user will be directed to another screen where he/she can edit the row data.
But to find a particular row, the user can click on the column heading to sort the table based on the column clicked. This is where the problem is, when the column heading is clicked and the table sorted, I am assuming the "Edit" string and the "Delete" string attached to each row will also be moved to a different place in the table based on the sort. But I guess, I am assuming wrong, even after sorting the table the "Edit" String and "Delete" String attached to row 1 does not move even though row 1 is moved to maybe row 8 in the table after the sort.
So, if i click on "Edit" on the first row, the click action is still attached to the row 1 data, instead of the new data which is now the first row after the sort..
I hope this explains my problem more clearly.
> This is what is happening:
>
> 1) reload data
> 2) invoke action
> 3) sort data
>
> You have to rearrange your logic to:
>
> 1) invoke action
> 2) reload data
> 3) sort data
>
> Or maybe (not recommended):
>
> 1) reload data
> 2) sort data
> 3) invoke action
>
> Clicking at row don't set the object itself by the
> way, but only the row index. Keep this in mind.