I have a page where a user can edit a lot of information, right now about 100 lines worth of DDLs and a text area, I want to update a data object after each change so that I only have to save to the database the changed rows instead of updating every row.
i.e. when the DDL value changes or when the text area data has changed (this is done in a pop up so that it will only be changed when 'Ok' is clicked) it will be stored into an array holding each updated row as an object. When the user hits save, it will only save the rows that were changed.
Right now im using AJAX so that its making a HTTPRequest, getting the array from the session and adding a new entry with the new value. Unfortunately I believe the page is stepping on itself at times and not keeping the data correct. I'm not sure why, but was wondering what would be the best way of implementing this, and if this is a good way of doing this.
Would a Java bean or anything else be better to represent the data object?
Would not accessing and storing i开发者_如何学运维n the session be faster and prevent this?
Java bean is very good for this purpose (as compared to java Map).
As I understand you want to call UPDATE only for items that has change, the best would be to implement equals() for that java bean class.
You have to store old values in session or anywhere else on server, to be able to determine what have change.
Anyway, you'll have to loop and do compare for each object:
if (!prevValue.equals(currValue)) {
DAO.update(currValue);
}
精彩评论