Rev 27 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
26 | moos | 1 | package ch.ffhs.webE.action; |
2 | |||
3 | import java.util.ArrayList; |
||
4 | import java.util.List; |
||
5 | |||
6 | import javax.servlet.http.HttpServletRequest; |
||
7 | |||
8 | import org.apache.struts2.ServletActionContext; |
||
9 | |||
10 | import ch.ffhs.webE.dao.RelationshipTypeDAO; |
||
11 | import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; |
||
12 | import ch.ffhs.webE.domain.RelationshipType; |
||
13 | |||
14 | import com.opensymphony.xwork2.ActionContext; |
||
15 | import com.opensymphony.xwork2.ActionSupport; |
||
16 | import com.opensymphony.xwork2.ModelDriven; |
||
17 | |||
18 | public class RelationshipTypeAction extends ActionSupport implements |
||
19 | ModelDriven<RelationshipType> |
||
20 | { |
||
21 | |||
22 | private static final long serialVersionUID = -3644691864156792139L; |
||
23 | |||
24 | private RelationshipType relType = new RelationshipType(); |
||
25 | private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>(); |
||
26 | private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); |
||
27 | |||
28 | @Override |
||
29 | public RelationshipType getModel() |
||
30 | { |
||
31 | return relType; |
||
32 | } |
||
33 | |||
34 | public String add() |
||
35 | { |
||
36 | relTypeDAO.saveRelationshipType(relType); |
||
37 | return SUCCESS; |
||
38 | } |
||
39 | |||
40 | public String list() |
||
41 | { |
||
42 | relTypeList = relTypeDAO.listRelationshipTypes(); |
||
43 | return SUCCESS; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * deletes a relationshipType, gets the ID from the id parameter that was |
||
48 | * submitted |
||
49 | * |
||
50 | * @return String - either success or error |
||
51 | */ |
||
52 | public String delete() |
||
53 | { |
||
54 | HttpServletRequest request = (HttpServletRequest) ActionContext |
||
55 | .getContext().get(ServletActionContext.HTTP_REQUEST); |
||
56 | |||
57 | //Make sure the ID from the request parameter is valid |
||
58 | int id = 0; |
||
59 | |||
60 | try |
||
61 | { |
||
62 | id = Integer.parseInt(request.getParameter("id")); |
||
63 | } |
||
64 | catch (Exception e) |
||
65 | { |
||
66 | return ERROR; |
||
67 | } |
||
68 | |||
69 | // Check for malicious ID values |
||
70 | if (id > 0) |
||
71 | { |
||
72 | relTypeDAO.deleteRelationshipType(id); |
||
73 | return SUCCESS; |
||
74 | } |
||
75 | else |
||
76 | { |
||
77 | return ERROR; |
||
78 | } |
||
79 | } |
||
80 | |||
81 | /* |
||
82 | * Getters and setters |
||
83 | */ |
||
84 | |||
85 | public RelationshipType getRelType() |
||
86 | { |
||
87 | return relType; |
||
88 | } |
||
89 | |||
90 | public void setRelType(RelationshipType relType) |
||
91 | { |
||
92 | this.relType = relType; |
||
93 | } |
||
94 | |||
95 | public List<RelationshipType> getRelTypeList() |
||
96 | { |
||
97 | return relTypeList; |
||
98 | } |
||
99 | |||
100 | public void setRelTypeList(List<RelationshipType> relTypeList) |
||
101 | { |
||
102 | this.relTypeList = relTypeList; |
||
103 | } |
||
104 | } |