Search in sources :

Example 61 with ActionMessage

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

the class TestTagUtils method testGetActionErrors1a.

// ------------------------------------------ getActionErrors()
// ActionErrors
public void testGetActionErrors1a() {
    ActionMessages actionErrors = new ActionMessages();
    actionErrors.add("prop", new ActionMessage("key.key"));
    request.setAttribute("errors", actionErrors);
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "errors");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        String val = null;
        int i = 0;
        for (Iterator iter = errors.get("prop"); iter.hasNext(); ) {
            ActionMessage error = (ActionMessage) iter.next();
            val = error.getKey();
            i++;
        }
        assertEquals("only 1 error", i, 1);
        assertEquals("errors prop should match", val, "key.key");
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) ActionMessage(org.apache.struts.action.ActionMessage) Iterator(java.util.Iterator)

Example 62 with ActionMessage

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

the class TestTagUtils method testActionMessages_getActionMessages_PageContext_String4.

// -- using String Array
public void testActionMessages_getActionMessages_PageContext_String4() {
    String[] vals = new String[] { "bar", "baz" };
    request.setAttribute("foo", vals);
    try {
        ActionMessages messages = tagutils.getActionMessages(pageContext, "foo");
        assertNotNull("messages should not be null", messages);
        assertNotNull("messages prop should not be null", messages.get("prop"));
        String key = null;
        int i = 0;
        for (Iterator iter = messages.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
            ActionMessage message = (ActionMessage) iter.next();
            key = message.getKey();
            Object[] values = message.getValues();
            assertNull((values));
            assertEquals("1st key should match", key, vals[i]);
            i++;
        }
        assertEquals("only 1 message", i, 2);
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Example 63 with ActionMessage

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

the class TestTagUtils method testGetActionErrors1b.

// String
public void testGetActionErrors1b() {
    request.setAttribute("foo", "bar");
    try {
        ActionMessages errors = tagutils.getActionMessages(pageContext, "foo");
        assertNotNull("errors should not be null", errors);
        assertNotNull("errors prop should not be null", errors.get("prop"));
        String key = null;
        int i = 0;
        for (Iterator iter = errors.get(ActionMessages.GLOBAL_MESSAGE); iter.hasNext(); ) {
            ActionMessage error = (ActionMessage) iter.next();
            key = error.getKey();
            Object[] values = error.getValues();
            assertNull(values);
            i++;
        }
        assertEquals("only 1 error", i, 1);
        assertEquals("key should match", key, "bar");
    } catch (JspException e) {
        fail(e.getMessage());
    }
}
Also used : JspException(javax.servlet.jsp.JspException) ActionMessages(org.apache.struts.action.ActionMessages) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage)

Example 64 with ActionMessage

use of org.apache.struts.action.ActionMessage 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 65 with ActionMessage

use of org.apache.struts.action.ActionMessage 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)

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