Memran
asked on
h:datatable row selection and multiple concurrent users
Hi :)
I am developing a simple web app, and using an <h:datatable> to display some data from the database, and provide links to edit and remove the data in a particular row.
The problem I have is that if one user modifies the data (eg removes a row) other users who are already viewing the table get undesired results when interacting with it.
Example, two users both viewing the table which contains three rows of data. If user #1 removes row 1, and then user #2 tries to edit or remove row 2, user #2 actually gets the data for row 3 (because row 1 is gone and the other rows move up).
I've attached a code snippet from the backing bean. opcoDataModel is the data for the table, selectForEdit is the method attached to the link on the row of data to be edited.
It seems to me that the method I am using to select the row is flawed, since the form, and hence the DataModel, get rebuilt before the form is sumbitted.
Any help is greatly appreciated.
I am developing a simple web app, and using an <h:datatable> to display some data from the database, and provide links to edit and remove the data in a particular row.
The problem I have is that if one user modifies the data (eg removes a row) other users who are already viewing the table get undesired results when interacting with it.
Example, two users both viewing the table which contains three rows of data. If user #1 removes row 1, and then user #2 tries to edit or remove row 2, user #2 actually gets the data for row 3 (because row 1 is gone and the other rows move up).
I've attached a code snippet from the backing bean. opcoDataModel is the data for the table, selectForEdit is the method attached to the link on the row of data to be edited.
It seems to me that the method I am using to select the row is flawed, since the form, and hence the DataModel, get rebuilt before the form is sumbitted.
Any help is greatly appreciated.
/**
* Method to get all opcos from the database
* @return DataModel for displaying in an h:dataTable
*/
public DataModel getOpcoDataModel() {
if(opcoDataModel == null) {
opcoDataModel = new ListDataModel();
}
Criteria criteria = new Criteria();
Collection<Opco> opcos = DBMethods.getCollection(criteria, Opco.class);
opcoDataModel.setWrappedData(opcos);
return opcoDataModel;
}
/**
* Method to populate the variables from the selected Opco
* @return "edit_opco", or "nothing found" if opco was null
*/
public String selectForEdit() {
Opco opco = (Opco)opcoDataModel.getRowData();
if(opco != null) {
opcoId = opco.getOpcoId();
companyName = opco.getCompanyName();
location = opco.getLocation();
contactEmail = opco.getContactEmail();
contactTel = opco.getContactTel();
webLink = opco.getWebLink();
return "edit_opco";
} else {
//should not be able to get here
return "nothing_found";
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was really hoping for a neat solution where I would pass the object, and not the ID (this is oop after all ;)), but since no such solution was forthcomming and time constraints are tight, I have gone with your reccommendation.
Have some points ;)
Thanks