This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Comparing Table Changes in a Web Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Comparing Table Changes in a Web Application" Watch "Comparing Table Changes in a Web Application" New topic
Author

Comparing Table Changes in a Web Application

Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
This is just used for an example..

My NameList.jsp has an EDIT button and a TABLE with these columns:

NAMECOMPANYGROUP

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...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
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")
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

That'd be fine as long as it doesn't replace server-side checking -- you can never trust any client-side validation.

Using JavaScript, it's pretty easy to keep track of whether the initial value has been changed or not. But this isn't the right forum for that. If that's what you're after, let me know and I'll move this over to the JavaScript forum.
Denise Advincula
Ranch Hand

Joined: Jan 01, 2007
Posts: 160
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing Table Changes in a Web Application