35,9 → 35,9 |
* |
* @return |
*/ |
public String add() |
public String addOrUpdate() |
{ |
userDAO.saveUser(user); |
userDAO.saveOrUpdateUser(user); |
return SUCCESS; |
} |
|
52,19 → 52,32 |
return SUCCESS; |
} |
|
public String edit() |
{ |
int id = getIdParameter(); |
|
if (id > 0) |
{ |
user = userDAO.listUserById(id); |
return SUCCESS; |
} |
else |
{ |
return ERROR; |
} |
} |
|
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted |
* with the HTTP request |
* Gets the ID Parameter for update / delete requests |
* |
* @return String - either SUCCESS or ERROR constant |
* @return int from the ID request. If not set or wrong, it gives back -1 |
*/ |
public String delete() |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
|
int id = 0; |
|
int id = -1; |
try |
{ |
id = Integer.parseInt(request.getParameter("id")); |
71,9 → 84,23 |
} |
catch (Exception e) |
{ |
return ERROR; |
// TODO: Logging - wrong parameter set |
} |
|
return id; |
} |
|
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted |
* with the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
*/ |
public String delete() |
{ |
|
int id = getIdParameter(); |
|
// Check for malicious ID values |
if (id > 0) |
{ |