package ch.ffhs.webE.action; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import ch.ffhs.webE.dao.RelationshipTypeDAO; import ch.ffhs.webE.dao.RelationshipTypeDAOImpl; import ch.ffhs.webE.domain.RelationshipType; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class RelationshipTypeAction extends ActionSupport implements ModelDriven { private static final long serialVersionUID = -3644691864156792139L; private RelationshipType relType = new RelationshipType(); private List relTypeList = new ArrayList(); private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl(); @Override public RelationshipType getModel() { return relType; } public String add() { relTypeDAO.saveRelationshipType(relType); return SUCCESS; } public String list() { relTypeList = relTypeDAO.listRelationshipTypes(); return SUCCESS; } /** * deletes a relationshipType, gets the ID from the id parameter that was * submitted * * @return String - either success or error */ public String delete() { HttpServletRequest request = (HttpServletRequest) ActionContext .getContext().get(ServletActionContext.HTTP_REQUEST); //Make sure the ID from the request parameter is valid int id = 0; try { id = Integer.parseInt(request.getParameter("id")); } catch (Exception e) { return ERROR; } // Check for malicious ID values if (id > 0) { relTypeDAO.deleteRelationshipType(id); return SUCCESS; } else { return ERROR; } } /* * Getters and setters */ public RelationshipType getRelType() { return relType; } public void setRelType(RelationshipType relType) { this.relType = relType; } public List getRelTypeList() { return relTypeList; } public void setRelTypeList(List relTypeList) { this.relTypeList = relTypeList; } }