use of org.apache.struts.action.ActionErrors in project head by mifos.
the class EditStatusAction method captureQuestionResponses.
@TransactionDemarcate(joinToken = true)
public ActionForward captureQuestionResponses(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, @SuppressWarnings("unused") final HttpServletResponse response) throws Exception {
request.setAttribute(METHODCALLED, "captureQuestionResponses");
ActionErrors errors = loanQuestionnaire.validateResponses(request, (EditStatusActionForm) form);
if (errors != null && !errors.isEmpty()) {
addErrors(request, errors);
return mapping.findForward(ActionForwards.captureQuestionResponses.toString());
}
return loanQuestionnaire.rejoinFlow(mapping);
}
use of org.apache.struts.action.ActionErrors in project sonarqube by SonarSource.
the class AbstractValidateActionForm method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Validate the properties of the form bean for this request. If there
* are any validation errors, execute the child commands in our chain;
* otherwise, proceed normally.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues, if there are
* no validation errors; otherwise <code>true</code>
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Set form valid until found otherwise
actionCtx.setFormValid(Boolean.TRUE);
// Is there a form bean for this request?
ActionForm actionForm = actionCtx.getActionForm();
if (actionForm == null) {
return false;
}
// Is validation disabled on this request?
ActionConfig actionConfig = actionCtx.getActionConfig();
if (!actionConfig.getValidate()) {
return false;
}
// Was this request cancelled?
if (isCancelled(actionCtx, actionConfig)) {
if (LOG.isDebugEnabled()) {
LOG.debug(" Cancelled transaction, skipping validation");
}
return false;
}
// Call the validate() method of this form bean
ActionErrors errors = validate(actionCtx, actionConfig, actionForm);
// If there were no errors, proceed normally
if ((errors == null) || (errors.isEmpty())) {
return false;
}
// Flag the validation failure and proceed
/* NOTE: Is there any concern that there might have already
* been errors, or that other errors might be coming?
*/
actionCtx.saveErrors(errors);
actionCtx.setFormValid(Boolean.FALSE);
return false;
}
use of org.apache.struts.action.ActionErrors in project sonarqube by SonarSource.
the class ValidateActionForm method validate.
// ------------------------------------------------------- Protected Methods
/**
* <p>Call the <code>validate()</code> method of the specified form bean,
* and return the resulting <code>ActionErrors</code> object.</p>
*
* @param context The context for this request
* @param actionForm The form bean for this request
*/
protected ActionErrors validate(ActionContext context, ActionConfig actionConfig, ActionForm actionForm) {
ServletActionContext saContext = (ServletActionContext) context;
ActionErrors errors = (actionForm.validate((ActionMapping) actionConfig, saContext.getRequest()));
// Special handling for multipart request
if ((errors != null) && !errors.isEmpty()) {
if (actionForm.getMultipartRequestHandler() != null) {
if (log.isTraceEnabled()) {
log.trace(" Rolling back multipart request");
}
actionForm.getMultipartRequestHandler().rollback();
}
}
return errors;
}
use of org.apache.struts.action.ActionErrors in project zoj by licheng.
the class EditProblemAction method validate.
/**
* Validates the form.
*
* @param mapping
* the action mapping.
* @param request
* the user request.
*
* @return collection of validation errors.
*/
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
ActionErrors errors = new ActionErrors();
this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
String name = form.getName();
String code = form.getCode();
if (name == null || name.trim().length() == 0) {
errors.add("name", new ActionMessage("ProblemForm.name.required"));
}
if (code == null || code.trim().length() == 0) {
errors.add("code", new ActionMessage("ProblemForm.code.required"));
}
if (!form.isUseContestDefault()) {
this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
}
List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
/*for (Object obj : problems) {
Problem p = (Problem) obj;
if (!form.getProblemId().equals("" + p.getId()) && p.getTitle().equals(name)) {
errors.add("name", new ActionMessage("ProblemForm.name.used"));
break;
}
}*/
for (Object obj : problems) {
Problem p = (Problem) obj;
if (!form.getProblemId().equals("" + p.getId()) && p.getCode().equals(code)) {
errors.add("code", new ActionMessage("ProblemForm.code.used"));
break;
}
}
return errors;
}
use of org.apache.struts.action.ActionErrors in project zoj by licheng.
the class AddProblemAction method validate.
/**
* Validates the form.
*
* @param mapping
* the action mapping.
* @param request
* the user request.
*
* @return collection of validation errors.
*/
public ActionErrors validate(ProblemForm form, ContextAdapter context) throws Exception {
ActionErrors errors = new ActionErrors();
this.checkInteger(form.getProblemId(), 0, Integer.MAX_VALUE, "id", errors);
String name = form.getName();
String code = form.getCode();
if (name == null || name.trim().length() == 0) {
errors.add("name", new ActionMessage("ProblemForm.name.required"));
}
if (code == null || code.trim().length() == 0) {
errors.add("code", new ActionMessage("ProblemForm.code.required"));
}
if (!form.isUseContestDefault()) {
this.checkInteger(form.getTimeLimit(), 0, 3600, "timeLimit", errors);
this.checkInteger(form.getMemoryLimit(), 0, 1024 * 1024, "memoryLimit", errors);
this.checkInteger(form.getOutputLimit(), 0, 100 * 1024, "outputLimit", errors);
this.checkInteger(form.getSubmissionLimit(), 0, 10 * 1024, "submissionLimit", errors);
}
List<Problem> problems = ContestManager.getInstance().getContestProblems(context.getContest().getId());
/*for (Object problem : problems) {
if (((Problem) problem).getTitle().equals(name)) {
errors.add("name", new ActionMessage("ProblemForm.name.used"));
break;
}
}*/
for (Object problem : problems) {
if (((Problem) problem).getCode().equals(code)) {
errors.add("code", new ActionMessage("ProblemForm.code.used"));
break;
}
}
return errors;
}
Aggregations