Solved

h:datatable row selection and multiple concurrent users

Posted on 2007-12-05
2
804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 125 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Postmortem reporting allow us to examine mistakes in a way that focuses on the situational aspects of a failure’s mechanism and the decision-making process of individuals proximate to the failure. Read our guide on how to handle IT post-mortem repor…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 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