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());
}
}
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());
}
}
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());
}
}
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");
}
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");
}
Aggregations