Rev 33 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 37 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | 5 | ||
6 | import javax.servlet.http.HttpServletRequest; |
6 | import javax.servlet.http.HttpServletRequest; |
7 | 7 | ||
8 | import org.apache.struts2.StrutsStatics; |
8 | import org.apache.struts2.StrutsStatics; |
9 | 9 | ||
10 | import ch.ffhs.webE.dao.UserDAOImpl; |
10 | import ch.ffhs.webE.dao.UserDAO; |
11 | import ch.ffhs.webE.domain.User; |
11 | import ch.ffhs.webE.domain.User; |
12 | 12 | ||
13 | import com.opensymphony.xwork2.Action; |
13 | import com.opensymphony.xwork2.Action; |
14 | import com.opensymphony.xwork2.ActionContext; |
14 | import com.opensymphony.xwork2.ActionContext; |
15 | import com.opensymphony.xwork2.ActionSupport; |
15 | import com.opensymphony.xwork2.ActionSupport; |
Line 20... | Line 20... | ||
20 | 20 | ||
21 | private static final long serialVersionUID = 1L; |
21 | private static final long serialVersionUID = 1L; |
22 | 22 | ||
23 | private User user = new User(); |
23 | private User user = new User(); |
24 | private List<User> userList = new ArrayList<User>(); |
24 | private List<User> userList = new ArrayList<User>(); |
25 | private final UserDAOImpl userDAO = new UserDAOImpl(); |
25 | private final UserDAO userDAO = new UserDAO(); |
- | 26 | ||
- | 27 | public boolean edit = false; |
|
- | 28 | public boolean added = false; |
|
- | 29 | public User savedUser; |
|
26 | 30 | ||
27 | @Override |
31 | @Override |
28 | public User getModel() |
32 | public User getModel() |
29 | {
|
33 | {
|
30 | return this.user; |
34 | return this.user; |
31 | }
|
35 | }
|
32 | 36 | ||
33 | /**
|
37 | /**
|
34 | * Executes the DB query to save the user
|
38 | * DB query for userList
|
35 | *
|
39 | *
|
36 | * @return
|
40 | * @return SUCCESS
|
37 | */
|
41 | */
|
38 | public String addOrUpdate() |
42 | public String list() |
39 | {
|
43 | {
|
40 | this.userDAO.saveOrUpdateUser(this.user); |
44 | this.userList = this.userDAO.getList(); |
41 | return Action.SUCCESS; |
45 | return Action.SUCCESS; |
42 | }
|
46 | }
|
43 | 47 | ||
44 | /**
|
48 | /**
|
45 | * DB query for userList
|
49 | * Executes the DB query to save the user
|
46 | *
|
50 | *
|
47 | * @return SUCCESS
|
51 | * @return
|
48 | */
|
52 | */
|
49 | public String list() |
53 | public String save() |
50 | {
|
54 | {
|
51 | this.userList = this.userDAO.listUser(); |
55 | this.userDAO.saveOrUpdate(this.user); |
- | 56 | this.savedUser = this.user; |
|
- | 57 | this.user = null; |
|
- | 58 | ||
- | 59 | this.list(); |
|
- | 60 | ||
52 | return Action.SUCCESS; |
61 | return Action.SUCCESS; |
53 | }
|
62 | }
|
54 | 63 | ||
55 | public String edit() |
64 | public String edit() |
56 | {
|
65 | {
|
57 | int id = this.getIdParameter(); |
66 | int id = this.getIdParameter(); |
58 | 67 | ||
- | 68 | String result = Action.ERROR; |
|
59 | if (id > 0) |
69 | if (id > 0) |
60 | {
|
70 | {
|
61 | this.user = this.userDAO.listUserById(id); |
71 | this.user = this.userDAO.getById(id); |
62 | return Action.SUCCESS; |
72 | this.edit = true; |
63 | }
|
- | |
64 | else
|
- | |
65 | {
|
- | |
66 | return Action.ERROR; |
73 | result = Action.SUCCESS; |
67 | }
|
74 | }
|
- | 75 | ||
- | 76 | this.list(); |
|
- | 77 | ||
- | 78 | return result; |
|
68 | }
|
79 | }
|
69 | 80 | ||
70 | /**
|
81 | /**
|
71 | * Gets the ID Parameter for update / delete requests
|
82 | * Gets the ID Parameter for update / delete requests
|
72 | *
|
83 | *
|
Line 102... | Line 113... | ||
102 | int id = this.getIdParameter(); |
113 | int id = this.getIdParameter(); |
103 | 114 | ||
104 | // Check for malicious ID values
|
115 | // Check for malicious ID values
|
105 | if (id > 0) |
116 | if (id > 0) |
106 | {
|
117 | {
|
107 | this.userDAO.deleteUser(id); |
118 | this.userDAO.delete(id); |
108 | return Action.SUCCESS; |
119 | return Action.SUCCESS; |
109 | }
|
120 | }
|
110 | else
|
121 | else
|
111 | {
|
122 | {
|
112 | return Action.ERROR; |
123 | return Action.ERROR; |