use of org.apache.struts.action.ActionMessage in project zoj by licheng.
the class DeleteProblemAction method execute.
/**
* Register.
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check problem
boolean isProblemset = context.getRequest().getRequestURI().endsWith("deleteProblem.do");
ActionForward forward = this.checkProblemAdminPermission(mapping, context, isProblemset);
if (forward != null) {
return forward;
}
Problem problem = context.getProblem();
ActionMessages messages = new ActionMessages();
ProblemPersistence problemPersistence = PersistenceManager.getInstance().getProblemPersistence();
problemPersistence.deleteProblem(problem.getId(), context.getUserProfile().getId());
messages.add("message", new ActionMessage("onlinejudge.deleteProblem.success"));
this.saveErrors(context.getRequest(), messages);
String back = isProblemset ? "showProblems" : "showContestProblems";
context.setAttribute("back", back + ".do?contestId=" + context.getContest().getId());
ContestManager.getInstance().refreshContest(context.getContest().getId());
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionMessage in project zoj by licheng.
the class EditLimitAction method execute.
/**
* Edit Role.
*
* <pre>
* </pre>
*
* @param mapping
* action mapping
* @param form
* action form
* @param request
* http servlet request
* @param response
* http servlet response
*
* @return action forward instance
*
* @throws Exception
* any errors happened
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
// check admin
ActionForward forward = this.checkAdmin(mapping, context);
if (forward != null) {
return forward;
}
LimitForm limitForm = (LimitForm) form;
if (limitForm.getId() == null || limitForm.getId().trim().length() == 0) {
Limit limit = PersistenceManager.getInstance().getContestPersistence().getDefaultLimit();
limitForm.setId("1");
limitForm.setTimeLimit("" + limit.getTimeLimit());
limitForm.setMemoryLimit("" + limit.getMemoryLimit());
limitForm.setSubmissionLimit("" + limit.getSubmissionLimit());
limitForm.setOutputLimit("" + limit.getOutputLimit());
return this.handleSuccess(mapping, context, "failure");
}
Limit limit = new Limit();
limit.setId(1);
limit.setTimeLimit(Integer.parseInt(limitForm.getTimeLimit()));
limit.setMemoryLimit(Integer.parseInt(limitForm.getMemoryLimit()));
limit.setOutputLimit(Integer.parseInt(limitForm.getOutputLimit()));
limit.setSubmissionLimit(Integer.parseInt(limitForm.getSubmissionLimit()));
PersistenceManager.getInstance().getContestPersistence().updateDefaultLimit(limit);
ActionMessages messages = new ActionMessages();
messages.add("success", new ActionMessage("onlinejudge.DefaultLimit.success"));
this.saveErrors(context.getRequest(), messages);
return this.handleSuccess(mapping, context, "success");
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class ImportTransactionsActionForm method validate.
/**
* Check to make sure the client hasn't exceeded the maximum allowed upload
* size inside of this validate method.
*/
@Override
public ActionErrors validate(@SuppressWarnings("unused") ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
// Do not validate if validation is not for upload
if (!request.getParameter("method").equals("upload")) {
// Using validate in Action classes creates confusion.
if (request.getAttribute("methodCalled") != null && request.getAttribute("methodCalled").equals("upload")) {
request.setAttribute(Globals.ERROR_KEY, request.getAttribute("uploadErrors"));
}
return null;
}
request.setAttribute("methodCalled", request.getParameter("method"));
request.setAttribute("uploadErrors", errors);
if ((importPluginName != null) && (importPluginName.length() < 1)) {
errors.add("importPluginName", new ActionMessage("errors.importexport.mandatory_selectbox"));
}
// has the maximum length been exceeded?
Boolean maxLengthExceeded = (Boolean) request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.importexport.toobig"));
} else if ((importTransactionsFile != null) && (importTransactionsFile.getFileName().length() < 1)) {
errors.add("importTransactionsFile", new ActionMessage("errors.importexport.mandatory_file"));
}
try {
// FIXME - remove call to service facade from form.
if (importTransactionsFile.getFileName() != null && ApplicationContextProvider.getBean(ImportTransactionsServiceFacade.class).isAlreadyImported(importTransactionsFile.getFileName())) {
errors.add("importTransactionsFile", new ActionMessage("errors.importexport.already_submitted"));
}
} catch (Exception e) {
e.printStackTrace();
}
return errors;
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class BulkEntryActionForm method validate.
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
logger.debug("BulkEntryActionForm.validate");
request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
ActionErrors errors = new ActionErrors();
if (request.getParameter(CollectionSheetEntryConstants.METHOD).equalsIgnoreCase(CollectionSheetEntryConstants.GETMETHOD)) {
java.sql.Date meetingDate = null;
try {
Object lastMeetingDate = SessionUtils.getAttribute("LastMeetingDate", request);
if (lastMeetingDate != null) {
meetingDate = new java.sql.Date(((java.util.Date) lastMeetingDate).getTime());
}
short isCenterHierarchyExists = (Short) SessionUtils.getAttribute(CollectionSheetEntryConstants.ISCENTERHIERARCHYEXISTS, request);
return mandatoryCheck(meetingDate, getUserContext(request), isCenterHierarchyExists);
} catch (PageExpiredException e) {
errors.add(ExceptionConstants.PAGEEXPIREDEXCEPTION, new ActionMessage(ExceptionConstants.PAGEEXPIREDEXCEPTION));
}
}
return errors;
}
use of org.apache.struts.action.ActionMessage in project head by mifos.
the class MeetingActionForm method validate.
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
String method = request.getParameter("method");
request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
ActionErrors errors = new ActionErrors();
try {
errors = validateFields(request, method);
} catch (ApplicationException ae) {
errors.add(ae.getKey(), new ActionMessage(ae.getKey(), ae.getValues()));
}
if (null != errors && !errors.isEmpty()) {
request.setAttribute(Globals.ERROR_KEY, errors);
request.setAttribute("methodCalled", method);
}
return errors;
}
Aggregations