throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
BuildingObject buildingObject = (BuildingObject) command;
if (buildingObject.getUser().getId() != null && !buildingObject.getUser().getId().equals(new Integer(-1))) {
buildingObject.setUser(userManager.getUser(buildingObject.getUser().getId().toString()));
} else {
buildingObject.setUser(userManager.getUserByUsername(request.getRemoteUser()));
}
boolean isNew = (buildingObject.getObjectId() == null);
Locale locale = request.getLocale();
Integer dangerCategoryId = buildingObject.getDangerCategory().getDangerCategoryId();
if (!dangerCategoryId.equals(new Integer(-1))) {
buildingObject.setDangerCategory(dangerCategoryManager.getDangerCategory(dangerCategoryId.toString()));
} else {
buildingObject.setDangerCategory(null);
}
//retrieving object type from base
if (!buildingObject.getObjectType().getObjectTypeId().equals(new Integer(-1))) {
buildingObject.setObjectType(objectTypeManager.getObjectType(buildingObject.getObjectType().getObjectTypeId().toString()));
} else {
buildingObject.setObjectType(null);
}
if (request.getParameter("delete") != null) {
buildingObjectManager.removeBuildingObject(buildingObject.getObjectId().toString());
saveMessage(request, getText("buildingObject.deleted", locale));
} else {
if (!isNew) {
//update only need properties from form
buildingObjectManager
.updateBuildingObjectByMainForm(
buildingObject.getObjectId(),
buildingObject);
} else {
buildingObjectManager.saveBuildingObject(buildingObject);
}
String key = (isNew) ? "buildingObject.added" : "buildingObject.updated";
saveMessage(request, getText(key, locale));
}
request.getSession().setAttribute("madeChanges", new Boolean(true));
request.getSession().setAttribute("pType", "buildingObject" );
request.getSession().setAttribute("pId", buildingObject.getObjectId() );
//request.getSession().setAttribute("isNew", true);
System.out.println("REDIRECT" + buildingObject.getDocLocation()+buildingObject.getObjectId());
return new ModelAndView("redirect:" + buildingObject.getDocLocation()+"?objectId="+buildingObject.getObjectId());
}