Subversion Repositories WebE

Compare Revisions

Last modification

Ignore whitespace Rev 30 → Rev 31

/trunk/src/ch/ffhs/webE/action/TermAction.java
0,0 → 1,166
package ch.ffhs.webE.action;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.StrutsStatics;
 
import ch.ffhs.webE.dao.TermDAO;
import ch.ffhs.webE.dao.TermDAOImpl;
import ch.ffhs.webE.domain.Term;
 
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
 
/**
* Implements actions applicable to term editing
*
* @author Thomas Lahn
*/
public class TermAction extends ActionSupport implements ModelDriven<Term>
{
private static final long serialVersionUID = -6659925652584240539L;
 
private Term term = new Term();
private List<Term> termList = new ArrayList<Term>();
private final TermDAO termDAO = new TermDAOImpl();
 
/*
* (non-Javadoc)
*
* @see com.opensymphony.xwork2.ModelDriven#getModel()
*/
public Term getModel()
{
return this.term;
}
 
/**
* Executes the DB query to save the user
*
* @return {@link Action#SUCCESS}
*/
public String addOrUpdate()
{
this.termDAO.saveOrUpdate(this.term);
return Action.SUCCESS;
}
 
/**
* DB query for userList
*
* @return SUCCESS
*/
public String list()
{
this.termList = this.termDAO.listTerm();
return Action.SUCCESS;
}
 
/**
* @return {@link Action#SUCCESS} if <var>id</var> > 0, {@link Action#ERROR}
* otherwise
*/
public String edit()
{
int id = this.getIdParameter();
 
if (id > 0)
{
this.term = this.termDAO.listTermById(id);
return Action.SUCCESS;
}
else
{
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(StrutsStatics.HTTP_REQUEST);
 
int id = -1;
try
{
id = Integer.parseInt(request.getParameter("id")); //$NON-NLS-1$
}
catch (Exception e)
{
/* 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 = this.getIdParameter();
 
/* Check for malicious ID values */
if (id > 0)
{
this.termDAO.deleteTerm(id);
return Action.SUCCESS;
}
else
{
return Action.ERROR;
}
}
 
/*
* Standard getters and setters
*/
 
/**
* @return The term edited with this instance
*/
public Term getTerm()
{
return this.term;
}
 
/**
* @param term
* The term edited with this instance
*/
public void setTerm(Term term)
{
this.term = term;
}
 
/**
* @return The list of terms edited with this instance
*/
public List<Term> getTermList()
{
return this.termList;
}
 
/**
* @param termList
* The list of terms edited with this instance
*/
public void setTermList(List<Term> termList)
{
this.termList = termList;
}
}
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property