I've a website which build using struts framework.
I want to keep track if there any changes made to value that previously save in database. So I want to compare value between actionForm and entities class.
The idea is something like this,
public class CompareValue extends org.apache.struts.action.Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
MyActionForm actionFrom = (MyActionForm) form;//form/view which contains new value that are going to be save to the database
EntitiesJpaController entitesController = new EntitiesJpaController();
EntitiesClass entities = entitesController.findEntitiesById(actionFrom.getId());//get data previously save to database
if(entities!=null){
if(!entities.getName().equals(actionForm.getName())){
System.out.println("Update applicant name");
}
if(!entities.getAddress().equals(actionForm.getAddress()){
System.out.println("Update applicant address");
}
if(!entities.getNrIcNo().equals(actionForm.getNrIcNo()){
System.out.println("Update applicant social security no");
}
/*log the changes somewhere*/
EntitiesClass entitiesWithNewValue = new EntitiesClass();
BeanUtil utilBean = new BeanUtil();
utilBean.copyProperties(entitiesWithNewValue, actionForm);//copy new value from actionForm to entitiesClasee
entitesController.edit(entitiesWithNewValue);//save new value to database
}
return mapping.findForward(SUCCESS);
}
}
but if my entities class only contains 3 fields then is not a problem to me. So I want solution where I can iterate to every fields in entities class and compare the value with new value from actionform.