Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 32 → Rev 33

/trunk/src/ch/ffhs/webE/action/UserAction.java
5,135 → 5,135
 
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 User user = new User();
private List<User> userList = new ArrayList<User>();
private final UserDAOImpl userDAO = new UserDAOImpl();
 
@Override
public User getModel()
{
return user;
}
@Override
public User getModel()
{
return this.user;
}
 
/**
* Executes the DB query to save the user
*
* @return
*/
public String addOrUpdate()
/**
* Executes the DB query to save the user
*
* @return
*/
public String addOrUpdate()
{
this.userDAO.saveOrUpdateUser(this.user);
return Action.SUCCESS;
}
 
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
{
this.userList = this.userDAO.listUser();
return Action.SUCCESS;
}
 
public String edit()
{
int id = this.getIdParameter();
 
if (id > 0)
{
userDAO.saveOrUpdateUser(user);
return SUCCESS;
this.user = this.userDAO.listUserById(id);
return Action.SUCCESS;
}
 
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
else
{
userList = userDAO.listUser();
return SUCCESS;
return Action.ERROR;
}
}
 
public String edit()
/**
* Gets the ID Parameter for update / delete requests
*
* @return int from the ID request. If not set or wrong, it gives back -1
*/
private int getIdParameter()
{
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(StrutsStatics.HTTP_REQUEST);
 
int id = -1;
try
{
int id = getIdParameter();
 
if (id > 0)
{
user = userDAO.listUserById(id);
return SUCCESS;
}
else
{
return ERROR;
}
id = Integer.parseInt(request.getParameter("id"));
}
 
/**
* Gets the ID Parameter for update / delete requests
*
* @return int from the ID request. If not set or wrong, it gives back -1
*/
private int getIdParameter()
catch (Exception e)
{
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(ServletActionContext.HTTP_REQUEST);
 
int id = -1;
try
{
id = Integer.parseInt(request.getParameter("id"));
}
catch (Exception e)
{
// TODO: Logging - wrong parameter set
}
 
return id;
// TODO: Logging - wrong parameter set
}
 
/**
* 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()
{
return id;
}
 
int id = getIdParameter();
/**
* 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()
{
 
// Check for malicious ID values
if (id > 0)
{
userDAO.deleteUser(id);
return SUCCESS;
}
else
{
return ERROR;
}
}
int id = this.getIdParameter();
 
/*
* Standard getters and setters
*/
 
public User getUser()
// Check for malicious ID values
if (id > 0)
{
return user;
this.userDAO.deleteUser(id);
return Action.SUCCESS;
}
 
public void setUser(User user)
else
{
this.user = user;
return Action.ERROR;
}
}
 
public List<User> getUserList()
{
return userList;
}
/*
* Standard getters and setters
*/
 
public void setUserList(List<User> userList)
{
this.userList = userList;
}
public User getUser()
{
return this.user;
}
 
public void setUser(User user)
{
this.user = user;
}
 
public List<User> getUserList()
{
return this.userList;
}
 
public void setUserList(List<User> userList)
{
this.userList = userList;
}
}