Search in sources :

Example 71 with ActionMessage

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");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Problem(cn.edu.zju.acm.onlinejudge.bean.Problem) ActionForward(org.apache.struts.action.ActionForward) ProblemPersistence(cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)

Example 72 with ActionMessage

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");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) LimitForm(cn.edu.zju.acm.onlinejudge.form.LimitForm) Limit(cn.edu.zju.acm.onlinejudge.bean.Limit) ActionForward(org.apache.struts.action.ActionForward)

Example 73 with ActionMessage

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;
}
Also used : ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Example 74 with ActionMessage

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;
}
Also used : PageExpiredException(org.mifos.framework.exceptions.PageExpiredException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors) Date(java.sql.Date) Date(java.sql.Date)

Example 75 with ActionMessage

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;
}
Also used : ApplicationException(org.mifos.framework.exceptions.ApplicationException) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

ActionMessage (org.apache.struts.action.ActionMessage)146 ActionErrors (org.apache.struts.action.ActionErrors)68 ActionMessages (org.apache.struts.action.ActionMessages)31 ResourceBundle (java.util.ResourceBundle)29 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)22 Locale (java.util.Locale)18 JspException (javax.servlet.jsp.JspException)11 Iterator (java.util.Iterator)10 ActionForward (org.apache.struts.action.ActionForward)9 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)8 List (java.util.List)8 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)7 ArrayList (java.util.ArrayList)7 DoubleConversionResult (org.mifos.framework.util.helpers.DoubleConversionResult)7 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 Date (java.sql.Date)6 PageExpiredException (org.mifos.framework.exceptions.PageExpiredException)6 ApplicationException (org.mifos.framework.exceptions.ApplicationException)5 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4