Search in sources :

Example 21 with ActionMessages

use of org.apache.struts.action.ActionMessages in project sonarqube by SonarSource.

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String5.

// String Array (thrown JspException)
public void testActionMessages_getActionMessages_PageContext_String5() {
    request.setAttribute("foo", new MockFormBean());
    ActionMessages messages = null;
    try {
        messages = tagutils.getActionMessages(pageContext, "foo");
        fail("should have thrown JspException");
    } catch (JspException e) {
        assertNull("messages should be null", messages);
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 22 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class RegisterAction 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 {
    if (!Features.register()) {
        context.getResponse().sendError(404);
        return null;
    }
    UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
    ProfileForm profileForm = (ProfileForm) form;
    if (profileForm.getHandle() == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    context.getRequest().getSession().invalidate();
    ActionMessages errors = this.validate(userPersistence, profileForm);
    if (errors.size() > 0) {
        return this.handleFailure(mapping, context, errors);
    }
    // create user profile
    UserProfile profile = profileForm.toUserProfile();
    userPersistence.createUserProfile(profile, 0);
    // create user perference
    UserPreference perference = profileForm.toUserPreference();
    perference.setId(profile.getId());
    userPersistence.createUserPreference(perference, 0);
    AuthorizationPersistence authorizationPersistence = PersistenceManager.getInstance().getAuthorizationPersistence();
    authorizationPersistence.addUserRole(profile.getId(), 2);
    context.getRequest().setAttribute("Countries", PersistenceManager.getInstance().getUserPersistence().getAllCountries());
    // get UserSecurity
    UserSecurity security = authorizationPersistence.getUserSecurity(profile.getId());
    context.setUserProfile(profile);
    context.setUserSecurity(security);
    context.setUserPreference(perference);
    ActionMessages messages = new ActionMessages();
    messages.add("message", new ActionMessage("onlinejudge.register.success"));
    this.saveErrors(context.getRequest(), messages);
    context.setAttribute("back", "");
    return this.handleSuccess(mapping, context, "success");
}
Also used : UserSecurity(cn.edu.zju.acm.onlinejudge.security.UserSecurity) UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionMessages(org.apache.struts.action.ActionMessages) ProfileForm(cn.edu.zju.acm.onlinejudge.form.ProfileForm) ActionMessage(org.apache.struts.action.ActionMessage) AuthorizationPersistence(cn.edu.zju.acm.onlinejudge.persistence.AuthorizationPersistence) UserPreference(cn.edu.zju.acm.onlinejudge.bean.UserPreference) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Example 23 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class ResetPasswordAction method execute.

/**
     * Edit Profile.
     * 
     * @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 {
    ResetPasswordForm passwordForm = (ResetPasswordForm) form;
    String code = passwordForm.getCode();
    UserPersistence userPersistence = PersistenceManager.getInstance().getUserPersistence();
    UserProfile user = null;
    if (code != null && code.trim().length() > 0) {
        user = userPersistence.getUserProfileByCode(code);
    }
    if (user == null) {
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.resetPassword.invalidCode"));
        this.saveErrors(context.getRequest(), messages);
        return this.handleSuccess(mapping, context, "message");
    }
    if (passwordForm.getPassword() == null) {
        return this.handleSuccess(mapping, context, "failure");
    }
    user.setPassword(passwordForm.getPassword());
    userPersistence.updateUserProfile(user, user.getId());
    userPersistence.deleteConfirmCode(user.getId(), user.getId());
    ActionMessages messages = new ActionMessages();
    messages.add("message", new ActionMessage("onlinejudge.resetPassword.success"));
    this.saveErrors(context.getRequest(), messages);
    return this.handleSuccess(mapping, context, "message");
}
Also used : UserProfile(cn.edu.zju.acm.onlinejudge.bean.UserProfile) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) ResetPasswordForm(cn.edu.zju.acm.onlinejudge.form.ResetPasswordForm) UserPersistence(cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)

Example 24 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class ShowDashboardAction method execute.

/**
     * ShowRolesAction.
     * 
     * @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 {
    ActionForward forward = this.checkAdmin(mapping, context);
    if (forward != null) {
        return forward;
    }
    LogSearchForm searchForm = (LogSearchForm) form;
    if (searchForm.getTimeStart() == null) {
        searchForm.setTimeStart(Utility.toTimestamp(new Date(System.currentTimeMillis() - 24 * 3600 * 1000)));
    }
    ActionMessages errors = searchForm.check();
    if (errors.size() > 0) {
        context.setAttribute("logs", new ArrayList<AccessLog>());
        return this.handleFailure(mapping, context, errors);
    }
    int page = Utility.parseInt(context.getRequest().getParameter("page"));
    if (page < 0) {
        page = 1;
    }
    int logsPerPage = 20;
    LogCriteria criteria = searchForm.toLogCriteria();
    List<AccessLog> logs = PerformanceManager.getInstance().searchLogs(criteria, (page - 1) * 20, logsPerPage, searchForm.getOrderBy());
    context.setAttribute("parameters", searchForm.toParameterMap());
    context.setAttribute("page", page);
    context.setAttribute("logsPerPage", logsPerPage);
    context.setAttribute("logs", logs);
    return this.handleSuccess(mapping, context, "success");
}
Also used : AccessLog(cn.edu.zju.acm.onlinejudge.util.AccessLog) LogSearchForm(cn.edu.zju.acm.onlinejudge.form.LogSearchForm) ActionMessages(org.apache.struts.action.ActionMessages) LogCriteria(cn.edu.zju.acm.onlinejudge.bean.request.LogCriteria) ActionForward(org.apache.struts.action.ActionForward) Date(java.util.Date)

Example 25 with ActionMessages

use of org.apache.struts.action.ActionMessages in project zoj by licheng.

the class BaseAction method handleFailure.

/**
     * Provides convenience method to handle errors.
     * 
     * @param mapping
     *            the action mapping that holds the forwards.
     * @param request
     *            the http servlet request.
     * @param messageKey
     *            the resource key to retrieve the error message.
     * @param errorKey
     *            the error key.
     * 
     * @return the failure forward.
     */
protected ActionForward handleFailure(ActionMapping mapping, ContextAdapter context, String errorKey, String resourceKey) {
    this.info(this.makeInfo(BaseAction.EXIT_OP, context.getOperator(), "failure"));
    ActionMessages errors = new ActionMessages();
    errors.add(errorKey, new ActionMessage(resourceKey));
    this.saveErrors(context.getRequest(), errors);
    return mapping.findForward("failure");
}
Also used : ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage)

Aggregations

ActionMessages (org.apache.struts.action.ActionMessages)47 ActionMessage (org.apache.struts.action.ActionMessage)31 JspException (javax.servlet.jsp.JspException)15 ActionForward (org.apache.struts.action.ActionForward)14 Iterator (java.util.Iterator)11 AbstractContest (cn.edu.zju.acm.onlinejudge.bean.AbstractContest)10 Problem (cn.edu.zju.acm.onlinejudge.bean.Problem)6 UserProfile (cn.edu.zju.acm.onlinejudge.bean.UserProfile)6 ContestPersistence (cn.edu.zju.acm.onlinejudge.persistence.ContestPersistence)4 UserPersistence (cn.edu.zju.acm.onlinejudge.persistence.UserPersistence)4 UserSecurity (cn.edu.zju.acm.onlinejudge.security.UserSecurity)4 Date (java.util.Date)4 Submission (cn.edu.zju.acm.onlinejudge.bean.Submission)3 UserPreference (cn.edu.zju.acm.onlinejudge.bean.UserPreference)3 ProblemPersistence (cn.edu.zju.acm.onlinejudge.persistence.ProblemPersistence)3 Contest (cn.edu.zju.acm.onlinejudge.bean.Contest)2 Course (cn.edu.zju.acm.onlinejudge.bean.Course)2 Reference (cn.edu.zju.acm.onlinejudge.bean.Reference)2 Language (cn.edu.zju.acm.onlinejudge.bean.enumeration.Language)2 LogCriteria (cn.edu.zju.acm.onlinejudge.bean.request.LogCriteria)2