Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

h:datatable row selection and multiple concurrent users

Posted on 2007-12-05
2
Medium Priority
?
818 Views
Last Modified: 2008-02-01
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.
/**
 * 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";
	}
}

Open in new window

0
Comment
Question by:Memran
2 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 375 total points
ID: 20417460
The way this is generally handled is
1.  Each row has a unique id -- _not_ the display row number -- by which it can be retrieved, updated, or deleted from the db.
2.  If a user deletes a row that turns out to have been already deleted, then the page redisplays without that row.  The application can tell that the row has already been deleted by another user because the delete request to the db used the unique id for the record, not the row id.
3.  The page redisplays the table in its current state, which means that the deleted row is now deleted.  Most applications don't try to explain to the user that the row had already been deleted by another user, but you could do that if it is a good thing for your application.

Seeing data that might be out of date is the nature of allowing multiple people to update the same data in the database.  It is almost never a problem for an application -- most people can understand that the last person to update a record wins.  Or, in the case of delete, the first person wins (or they both win, since the goal was a delete).

If you have an application where you need to have perfect information displayed to the user, then you have to lock the table from updates by other people while user A is looking at/editing it.  As soon as there is some sort of signal from user A that they are done, then the table is free for edits by user B -- and the table must redisplay before user B begins his/her edit.
0
 

Author Comment

by:Memran
ID: 20440323
Thanks for your reply.
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
Following on from our article on "The Murky World of Consent and opt in", we thought we would issue some helpful guidance, not only on consent itself but knowing what information you are capturing, what you are doing with this data and how you can p…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question