Solved

h:datatable row selection and multiple concurrent users

Posted on 2007-12-05
2
796 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven scope 1 126
library class in java 1 90
How can I   ajax html table  rows? 20 62
HTTPSessionBindingListernter not configured in deployment descriptor 2 36
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now