Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

h:datatable row selection and multiple concurrent users

Posted on 2007-12-05
2
Medium Priority
?
812 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

721 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