Advertisement
Guest User

ObjectAction

a guest
Nov 12th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. public class ObjectAction extends ActionSupport implements Preparable {
  2.  
  3.     /** Serial version UID. */
  4.     private static final long serialVersionUID = 8225105390632222245L;
  5.  
  6.     /** The current exam */
  7.     private Object object;
  8.  
  9.     /** The object's identifier selected by the user */
  10.     private Long objectId;
  11.  
  12.     /** The AttachedObject that was edited/added */
  13.     private AttachedObject attachedObject;
  14.  
  15.     /** The object service. */
  16.     @Autowired
  17.     private ObjectService objectService;
  18.  
  19.     private ArrayList<String> ojectTypes;
  20.  
  21.     @Override
  22.     public void prepare() throws Exception {
  23.         objectTypes = new ArrayList<String>();
  24.         ObjectType[] allTypes = ObjectType.values();
  25.         for (ObjectType objectType : allTypes) {
  26.             objectTypes.add(objectType.toString());
  27.         }
  28.  
  29.         Long id = 0l;
  30.         if (examId != null) {
  31.             id = objectId;
  32.         } else if (attachedObject != null) {
  33.             id = attachedObject.getObject().getId();
  34.         }
  35.         if (id == (long) 0) {
  36.         } else {
  37.             object = objectService.loadObject(id);
  38.         }
  39.     }
  40.    
  41.     /**
  42.      * Saves the object to the database.
  43.      *
  44.      * @return the result string.
  45.      */
  46.     public String save() {
  47.         objectService.saveObject(object);
  48.         return SUCCESS;
  49.     }
  50.  
  51.     /**
  52.      * Deletes the selected object from the database.
  53.      *
  54.      * @return the result string.
  55.      */
  56.     public String delete() {
  57.         exam = objectService.loadObject(objectId);
  58.         if (object != null) {
  59.             objectService.deleteObject(object);
  60.         }
  61.         return SUCCESS;
  62.     }
  63.  
  64.         /**
  65.      * Displays the selected object in the object form.
  66.      *
  67.      * @return the result string.
  68.      */
  69.     public String load() {
  70.         return SUCCESS;
  71.     }
  72.  
  73.     public String cancel() {
  74.         return SUCCESS;
  75.     }
  76.  
  77.     @Override
  78.     public void validate() {
  79.         // If the object is not set, the object ID has to be set.
  80.         if (object == null && objectId == null) {
  81.             if (attachedObject == null) {
  82.                 addActionError(getText("msg.selectObject"));
  83.             }
  84.         }
  85.     }
  86.  
  87.     /** all getters and setters */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement