public class AttachedObjectAction extends ActionSupport implements Preparable { /** Serial version UID */ private static final long serialVersionUID = 4311471608420886112L; /** The current attachedObject*/ private AttachedObject attachedObject; /** The attachedObject's identifier selected by the user */ private Long attachedObjectId; /** The attachedObjectservice. */ @Autowired private AttachedObjectService attachedObjectService; private ArrayList objectTypes; @Override public void prepare() throws Exception { objectTypes = new ArrayList(); ObjectType[] allTypes = ObjectType.values(); for (ObjectType objectType : allTypes) { objectTypes.add(objectType.toString()); } } /** * Saves the attachedObject to the database. * * @return the result string. */ public String save() { attachedObjectService.saveAttachedObject(attachedObject); return SUCCESS; } /** * Deletes the selected attachedObject from the database. * * @return the result string. */ public String delete() { attachedObject = attachedObjectService.loadAttachedObject(attachedObjectId); if (attachedObject != null) { attachedObjectService.deleteAttachedObject(attachedObject); } return SUCCESS; } /** * Displays the selected attachedObject in the attachedObject form. * * @return the result string. */ public String load() { attachedObject = attachedObjectService.loadAttachedObject(attachedObjectId); return SUCCESS; } public String cancel() { return SUCCESS; } @Override public void validate() { // If the attachedObject is not set, the attachedObject ID has to be set. if (attachedObject == null && attachedObjectId == null) { addActionError(getText("msg.selectAttachedObject")); } } }