5,29 → 5,29 |
|
import javax.servlet.http.HttpServletRequest; |
|
import org.apache.struts2.ServletActionContext; |
import org.apache.struts2.StrutsStatics; |
|
import ch.ffhs.webE.dao.UserDAOImpl; |
import ch.ffhs.webE.domain.User; |
|
import com.opensymphony.xwork2.Action; |
import com.opensymphony.xwork2.ActionContext; |
import com.opensymphony.xwork2.ActionSupport; |
import com.opensymphony.xwork2.ModelDriven; |
import ch.ffhs.webE.dao.UserDAO; |
import ch.ffhs.webE.dao.UserDAOImpl; |
|
import ch.ffhs.webE.domain.User; |
|
public class UserAction extends ActionSupport implements ModelDriven<User> |
{ |
|
private static final long serialVersionUID = -6659925652584240539L; |
private static final long serialVersionUID = 1L; |
|
private User user = new User(); |
private List<User> userList = new ArrayList<User>(); |
private UserDAO userDAO = new UserDAOImpl(); |
private final UserDAOImpl userDAO = new UserDAOImpl(); |
|
@Override |
public User getModel() |
{ |
return user; |
return this.user; |
} |
|
/** |
37,8 → 37,8 |
*/ |
public String addOrUpdate() |
{ |
userDAO.saveOrUpdateUser(user); |
return SUCCESS; |
this.userDAO.saveOrUpdateUser(this.user); |
return Action.SUCCESS; |
} |
|
/** |
48,22 → 48,22 |
*/ |
public String list() |
{ |
userList = userDAO.listUser(); |
return SUCCESS; |
this.userList = this.userDAO.listUser(); |
return Action.SUCCESS; |
} |
|
public String edit() |
{ |
int id = getIdParameter(); |
int id = this.getIdParameter(); |
|
if (id > 0) |
{ |
user = userDAO.listUserById(id); |
return SUCCESS; |
this.user = this.userDAO.listUserById(id); |
return Action.SUCCESS; |
} |
else |
{ |
return ERROR; |
return Action.ERROR; |
} |
} |
|
75,7 → 75,7 |
private int getIdParameter() |
{ |
HttpServletRequest request = (HttpServletRequest) ActionContext |
.getContext().get(ServletActionContext.HTTP_REQUEST); |
.getContext().get(StrutsStatics.HTTP_REQUEST); |
|
int id = -1; |
try |
91,8 → 91,8 |
} |
|
/** |
* deletes a user, gets the ID from the "id" parameter that was submitted |
* with the HTTP request |
* deletes a user, gets the ID from the "id" parameter that was submitted with |
* the HTTP request |
* |
* @return String - either SUCCESS or ERROR constant |
*/ |
99,17 → 99,17 |
public String delete() |
{ |
|
int id = getIdParameter(); |
int id = this.getIdParameter(); |
|
// Check for malicious ID values |
if (id > 0) |
{ |
userDAO.deleteUser(id); |
return SUCCESS; |
this.userDAO.deleteUser(id); |
return Action.SUCCESS; |
} |
else |
{ |
return ERROR; |
return Action.ERROR; |
} |
} |
|
119,7 → 119,7 |
|
public User getUser() |
{ |
return user; |
return this.user; |
} |
|
public void setUser(User user) |
129,7 → 129,7 |
|
public List<User> getUserList() |
{ |
return userList; |
return this.userList; |
} |
|
public void setUserList(List<User> userList) |