View Javadoc

1   package com.panogenesis.webapp.action;
2   
3   import java.util.Locale;
4   
5   import javax.servlet.http.HttpServletRequest;
6   import javax.servlet.http.HttpServletResponse;
7   
8   import org.apache.commons.lang.StringUtils;
9   
10  import com.panogenesis.Constants;
11  import com.panogenesis.model.ProjectStatus;
12  import com.panogenesis.service.LookupManager;
13  import com.panogenesis.service.ProjectStatusManager;
14  import com.panogenesis.service.impl.LookupManagerImpl;
15  
16  import org.springframework.validation.BindException;
17  import org.springframework.web.servlet.ModelAndView;
18  import org.springframework.web.servlet.view.RedirectView;
19  
20  public class ProjectStatusFormController extends BaseFormController {
21      private ProjectStatusManager projectStatusManager = null;
22  
23      public void setProjectStatusManager(ProjectStatusManager projectStatusManager) {
24          this.projectStatusManager = projectStatusManager;
25      }
26  
27      protected Object formBackingObject(HttpServletRequest request)
28      throws Exception {
29          String id = request.getParameter("id");
30          ProjectStatus projectStatus = null;
31  
32          if (!StringUtils.isEmpty(id)) {
33              projectStatus = projectStatusManager.getProjectStatus(id);
34          } else {
35              projectStatus = new ProjectStatus();
36          }
37  
38          return projectStatus;
39      }
40  
41      public ModelAndView onSubmit(HttpServletRequest request,
42                                   HttpServletResponse response, Object command,
43                                   BindException errors)
44      throws Exception {
45          if (log.isDebugEnabled()) {
46              log.debug("entering 'onSubmit' method...");
47          }
48  
49          ProjectStatus projectStatus = (ProjectStatus) command;
50          boolean isNew = (projectStatus.getId() == null);
51          String success = getSuccessView();
52          Locale locale = request.getLocale();
53  
54          if (request.getParameter("delete") != null) {
55              projectStatusManager.removeProjectStatus(projectStatus.getId().toString());
56  
57              saveMessage(request, getText("projectStatus.deleted", locale));
58          } else {
59              projectStatusManager.saveProjectStatus(projectStatus);
60  
61              String key = (isNew) ? "projectStatus.added" : "projectStatus.updated";
62              
63               saveMessage(request, getText(key, locale));
64  
65              if (!isNew) {
66                  success = "editProjectStatus.html?id=" + projectStatus.getId();
67              }
68          }
69  
70          return new ModelAndView(new RedirectView(success));
71      }
72  }