Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 33 → Rev 34

/trunk/src/ch/ffhs/webE/action/RelationshipTypeAction.java
5,125 → 5,126
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
 
import ch.ffhs.webE.dao.RelationshipTypeDAO;
import ch.ffhs.webE.dao.RelationshipTypeDAOImpl;
import ch.ffhs.webE.domain.RelationshipType;
 
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
 
public class RelationshipTypeAction extends ActionSupport implements
ModelDriven<RelationshipType>
ModelDriven<RelationshipType>
{
 
private static final long serialVersionUID = -3644691864156792139L;
private static final long serialVersionUID = -3644691864156792139L;
 
private RelationshipType relType = new RelationshipType();
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>();
private RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl();
private RelationshipType relType = new RelationshipType();
private List<RelationshipType> relTypeList = new ArrayList<RelationshipType>();
private final RelationshipTypeDAO relTypeDAO = new RelationshipTypeDAOImpl();
 
@Override
public RelationshipType getModel()
{
return relType;
}
@Override
public RelationshipType getModel()
{
return this.relType;
}
 
public String addOrUpdate()
{
relTypeDAO.saveOrUpdateRelType(relType);
return SUCCESS;
}
public String addOrUpdate()
{
this.relTypeDAO.saveOrUpdateRelType(this.relType);
return Action.SUCCESS;
}
 
public String list()
public String list()
{
this.relTypeList = this.relTypeDAO.getRelTypes();
return Action.SUCCESS;
}
 
public String edit()
{
int id = this.getIdParameter();
 
if (id > 0)
{
relTypeList = relTypeDAO.listRelationshipTypes();
return SUCCESS;
this.relType = this.relTypeDAO.getRelTypeById(id);
return Action.SUCCESS;
}
public String edit()
else
{
int id = getIdParameter();
 
if (id > 0)
{
relType = relTypeDAO.listRelTypeById(id);
return SUCCESS;
}
else
{
return ERROR;
}
return Action.ERROR;
}
/**
* 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(ServletActionContext.HTTP_REQUEST);
}
 
int id = -1;
try
{
id = Integer.parseInt(request.getParameter("id"));
}
catch (Exception e)
{
// TODO: Logging - wrong parameter set
}
/**
* 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);
 
return id;
int id = -1;
try
{
id = Integer.parseInt(request.getParameter("id"));
}
 
/**
* deletes a relationshipType, gets the ID from the id parameter that was
* submitted
*
* @return String - either success or error
*/
public String delete()
catch (Exception e)
{
int id = getIdParameter();
 
// Check for malicious ID values
if (id > 0)
{
relTypeDAO.deleteRelationshipType(id);
return SUCCESS;
}
else
{
return ERROR;
}
// TODO: Logging - wrong parameter set
}
 
/*
* Getters and setters
*/
return id;
}
 
public RelationshipType getRelType()
{
return relType;
}
/**
* deletes a relationshipType, gets the ID from the id parameter that was
* submitted
*
* @return String - either success or error
*/
public String delete()
{
int id = this.getIdParameter();
 
public void setRelType(RelationshipType relType)
// Check for malicious ID values
if (id > 0)
{
this.relType = relType;
this.relTypeDAO.deleteRelationshipType(id);
return Action.SUCCESS;
}
 
public List<RelationshipType> getRelTypeList()
else
{
return relTypeList;
return Action.ERROR;
}
}
 
public void setRelTypeList(List<RelationshipType> relTypeList)
{
this.relTypeList = relTypeList;
}
/*
* Getters and setters
*/
 
public RelationshipType getRelType()
{
return this.relType;
}
 
public void setRelType(RelationshipType relType)
{
this.relType = relType;
}
 
public List<RelationshipType> getRelTypeList()
{
return this.relTypeList;
}
 
public void setRelTypeList(List<RelationshipType> relTypeList)
{
this.relTypeList = relTypeList;
}
}