Subversion Repositories WebE

Rev

Rev 27 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 34
Line 3... Line 3...
3
import java.util.ArrayList;
3
import java.util.ArrayList;
4
import java.util.List;
4
import java.util.List;
5
5
6
import javax.servlet.http.HttpServletRequest;
6
import javax.servlet.http.HttpServletRequest;
7
7
8
import org.apache.struts2.ServletActionContext;
8
import org.apache.struts2.StrutsStatics;
9
9
10
import ch.ffhs.webE.dao.RelationshipTypeDAO;
10
import ch.ffhs.webE.dao.RelationshipTypeDAO;
11
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl;
11
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl;
12
import ch.ffhs.webE.domain.RelationshipType;
12
import ch.ffhs.webE.domain.RelationshipType;
13
13
-
 
14
import com.opensymphony.xwork2.Action;
14
import com.opensymphony.xwork2.ActionContext;
15
import com.opensymphony.xwork2.ActionContext;
15
import com.opensymphony.xwork2.ActionSupport;
16
import com.opensymphony.xwork2.ActionSupport;
16
import com.opensymphony.xwork2.ModelDriven;
17
import com.opensymphony.xwork2.ModelDriven;
17
18
18
public class RelationshipTypeAction extends ActionSupport implements
19
public class RelationshipTypeAction extends ActionSupport implements
Line 21... Line 22...
21
22
22
    private static final long serialVersionUID = -3644691864156792139L;
23
  private static final long serialVersionUID = -3644691864156792139L;
23
24
24
    private RelationshipType relType = new RelationshipType();
25
  private RelationshipType relType = new RelationshipType();
25
    private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>();
26
  private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>();
26
    private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl();
27
  private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl();
27
28
28
    @Override
29
  @Override
29
    public RelationshipType getModel()
30
  public RelationshipType getModel()
30
    {
31
  {
31
        return relType;
32
    return this.relType;
32
    }
33
  }
33
34
34
    public String addOrUpdate()
35
  public String addOrUpdate()
35
    {
36
  {
36
        relTypeDAO.saveOrUpdateRelType(relType);
37
    this.relTypeDAO.saveOrUpdateRelType(this.relType);
37
        return SUCCESS;
38
    return Action.SUCCESS;
38
    }
39
  }
39
40
40
    public String list()
41
  public String list()
41
    {
42
  {
42
        relTypeList = relTypeDAO.listRelationshipTypes();
43
    this.relTypeList = this.relTypeDAO.getRelTypes();
43
        return SUCCESS;
44
    return Action.SUCCESS;
44
    }
45
  }
45
   
46
46
    public String edit()
47
  public String edit()
47
    {
48
  {
48
        int id = getIdParameter();
49
    int id = this.getIdParameter();
49
50
50
        if (id > 0)
51
    if (id > 0)
51
        {
52
    {
52
            relType = relTypeDAO.listRelTypeById(id);
53
      this.relType = this.relTypeDAO.getRelTypeById(id);
53
            return SUCCESS;
54
      return Action.SUCCESS;
54
        }
55
    }
55
        else
56
    else
56
        {
57
    {
57
            return ERROR;
58
      return Action.ERROR;
58
        }
59
    }
59
    }
60
  }
60
   
61
61
    /**
62
  /**
62
     * Gets the ID Parameter for update / delete requests
63
   * Gets the ID Parameter for update / delete requests
Line 64... Line 65...
64
     * @return int from the ID request. If not set or wrong, it gives back -1
65
   * @return int from the ID request. If not set or wrong, it gives back -1
65
     */
66
   */
66
    private int getIdParameter()
67
  private int getIdParameter()
67
    {
68
  {
68
        HttpServletRequest request = (HttpServletRequest) ActionContext
69
    HttpServletRequest request = (HttpServletRequest) ActionContext
69
                .getContext().get(ServletActionContext.HTTP_REQUEST);
70
        .getContext().get(StrutsStatics.HTTP_REQUEST);
70
71
71
        int id = -1;
72
    int id = -1;
72
        try
73
    try
73
        {
74
    {
74
            id = Integer.parseInt(request.getParameter("id"));
75
      id = Integer.parseInt(request.getParameter("id"));
Line 87... Line 88...
87
     *
88
   *
88
     * @return String - either success or error
89
   * @return String - either success or error
89
     */
90
   */
90
    public String delete()
91
  public String delete()
91
    {
92
  {
92
        int id = getIdParameter();
93
    int id = this.getIdParameter();
93
94
94
        // Check for malicious ID values
95
    // Check for malicious ID values
95
        if (id > 0)
96
    if (id > 0)
96
        {
97
    {
97
            relTypeDAO.deleteRelationshipType(id);
98
      this.relTypeDAO.deleteRelationshipType(id);
98
            return SUCCESS;
99
      return Action.SUCCESS;
99
        }
100
    }
100
        else
101
    else
101
        {
102
    {
102
            return ERROR;
103
      return Action.ERROR;
103
        }
104
    }
104
    }
105
  }
105
106
106
    /*
107
  /*
107
     * Getters and setters
108
   * Getters and setters
108
     */
109
   */
109
110
110
    public RelationshipType getRelType()
111
  public RelationshipType getRelType()
111
    {
112
  {
112
        return relType;
113
    return this.relType;
113
    }
114
  }
114
115
115
    public void setRelType(RelationshipType relType)
116
  public void setRelType(RelationshipType relType)
116
    {
117
  {
117
        this.relType = relType;
118
    this.relType = relType;
118
    }
119
  }
119
120
120
    public List<RelationshipType> getRelTypeList()
121
  public List<RelationshipType> getRelTypeList()
121
    {
122
  {
122
        return relTypeList;
123
    return this.relTypeList;
123
    }
124
  }
124
125
125
    public void setRelTypeList(List<RelationshipType> relTypeList)
126
  public void setRelTypeList(List<RelationshipType> relTypeList)
126
    {
127
  {
127
        this.relTypeList = relTypeList;
128
    this.relTypeList = relTypeList;