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