It depends where you want to do. You can either do it client side or server side. For client site refer to post below.
What is the best way to track changes in a form via javascript?
for server side
If you are ORM then you can use SaveOrUpdate() call. Read what it does.
OR
Make 2 dataTransfer objects lets call them loadTimeObject and submitObject.
Assuming flow and domain model here.
- Edit details button click -> get the row id or primary key/unique
row/or id.
- Load data to fields by make Ajax call or if data is already available in JavaScript object, using row/object id - refer this as loadTimeObject
- User makes/does not make changes and click on submit. Load the form fields to submitObject. In Java validate if the loadTimeObject and submitObject differ? Track what fields changes and persist them in DB.
Hint:You may use Apache Commons Beanutils compareObjects(Object loadTimeObject , Object submitObject) methods.
OR
use java reflection to compare objects.
public static <T> void Compare(T source, T target) throws IllegalArgumentException, IllegalAccessException {
if(source == null) {
throw new IllegalArgumentException("Null argument not excepted at this point");
}
Field[] fields = source.getClass().getFields();
Object sourceObject;
Object targetObject;
for(Field field : fields){
sourceObject = field.get(source);
targetObject = field.get(target);
//Compare the object
}
}