简体   繁体   中英

Best practices for indicating a field has been modified in GWT

My application has several key objects whose fields are accessed by multiple presenters. Currently, my use of getters/setters is limited to cases in which validation is required. I'd like to keep track of whether the field values have been updated (and therefore require database update). To do so, I'm considering adding boolean flags isDirty (to indicate that the current value differs from the retrieved or default) and isDeleted (to indicate whether the record(s) associated with an object should be removed). Adding such flags to the class would require either (a) using setters and setting the flag values in the setter when the field is updated) or (b) Forgoing setters but requiring any code that modified a field value to also set the flags (clearly error prone). Is there a more elegant way to keep track of field meta-data?

If object is stored as session attribute then you can monitor the attribute state (added/removed/replaced) in session scope using HttpSessionAttributeListener .

I have already posted a sample code on Servlets-Session attribute . Please have a look.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM