My NameList.jsp has an EDIT button and a TABLE with these columns:
The values for these are obtained from the database. The NAME column values are all links, which when clicked will invoke a popup with a textbox and a prompt to enter a new name. After the click of the popup's OK button, the name displayed in the table will be changed to the new name specified in the popup. When the NameList.jsp's EDIT button is clicked, all the changes in the table will then be updated in the database.
But what if I want to know that the table has changed? Like if the user has clicked the EDIT button but no changes has been made. If that's the case, then no update invocation should be made. And to make it more bloody, I need to know if EACH rows have changed.
I was thinking of having a hidden table, where the original values will be placed. And upon the click of EDIT, the hidden table and the visible table will be compared one by one. Or a hidden text field perhaps, where the vector is represented as String and will be compared all the way.
But I don't think any of these is a good idea.
Can anybody suggest me a more sophisticated way for this kind of scenario?
Thank you very much in advance!
[ July 03, 2008: Message edited by: Denise Saulon ]
[ July 03, 2008: Message edited by: Denise Saulon ] [ July 03, 2008: Message edited by: Denise Saulon ]
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCMJEA in progress...
I don't think it's a good idea to be doing this in the UI layer in the first place. This is something that should be determined by the backend model code. [ July 03, 2008: Message edited by: Bear Bibeault ]
However, what if it is really required to do a client-side validation that when you pressed the Edit button, the system will return a message like this: "No modifications found" (or simply "Nothing changed")
That'd be fine as long as it doesn't replace server-side checking -- you can never trust any client-side validation.
Joined: Jan 01, 2007
Yes... I would really like to know how.
(I got confused where to put this topic... Anyhow, please move this topic to the more appropriate forum. Thank you very much! ) [ July 03, 2008: Message edited by: Denise Saulon ]
There are any number of ways to do this, but one I'd probably try would be to traverse the fields at page-load time and record the original values as an extra property on each field (sometimes called an "expando"). Then, at form-submit time, you can compare the current values of the fields with the originals and collect the names of the changed fields. These names could be sent back to the server in a hidden input as a comma-delimited list or something if needed.