确定Object是否已更改的最佳方法是什么?

确定Object是否已更改的最佳方法是什么?

问题描述:

我在Java Web应用程序(JSF1.2,RichFaces)中创建了一些savebean功能。它使用JAXB将其转换为XML字符串,然后将其存储在数据库中。如果用户将其加载回来,我想通知用户是否更改了(bean)内容并且应该再次保存。

I made some "save" bean functionality in my Java Web Application (JSF1.2, RichFaces). It is using JAXB to turn it into an XML string and then it is stored in the database. If the user loads this back, I want to notify the user if the (bean)content is changed and it should be saved again.

我的想法是覆盖 hashCode()函数'with' org.apache.commons.lang.builder.HashCodeBuilder ,但是我有很多字段和儿童元素。
有没有其他办法可以处理这种功能?

My idea is to override the hashCode() function 'with' org.apache.commons.lang.builder.HashCodeBuilder, however I have lots of fields and child elements. Is there any other way to handle this kind of functionality?

编辑

比较在另一个视图上完成!

"Comparison" is done on another view!

任何帮助都将不胜感激!

Any help would be appreciated!

你可以在bean中添加一个 boolean dirty; 标志,将其设置为 true 在你的setter中并在重新加载和保存后清除它。

You could add a boolean dirty; flag to the bean, set it to true in your setters and clear it during a reload and after a save.