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 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 head by mifos.
the class SavingsClosureAction 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 = closeSavingsQuestionnaire.validateResponses(request, (SavingsClosureActionForm) form);
if (errors != null && !errors.isEmpty()) {
addErrors(request, errors);
return mapping.findForward(ActionForwards.captureQuestionResponses.toString());
}
return closeSavingsQuestionnaire.rejoinFlow(mapping);
}
use of org.apache.struts.action.ActionErrors in project head by mifos.
the class SavingsActionForm method validate.
@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
String method = request.getParameter("method");
ActionErrors errors = new ActionErrors();
String mandatoryAmount = getLocalizedMessage(SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY);
request.setAttribute(Constants.CURRENTFLOWKEY, request.getParameter(Constants.CURRENTFLOWKEY));
if (method.equals("getPrdOfferings") || method.equals("create") || method.equals("edit") || method.equals("update") || method.equals("get") || method.equals("validate")) {
} else {
errors.add(super.validate(mapping, request));
if (method.equals("preview") || method.equals("editPreview")) {
try {
SavingsOfferingBO savingsOffering = (SavingsOfferingBO) SessionUtils.getAttribute(SavingsConstants.PRDOFFERING, request);
if (savingsOffering.getSavingsType().getId().equals(SavingsType.MANDATORY.getValue()) && StringUtils.isBlank(getRecommendedAmount())) {
// check for mandatory amount
errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
}
if (StringUtils.isNotBlank(getRecommendedAmount())) {
if (savingsOffering.getSavingsType().equals(SavingsType.MANDATORY)) {
validateAmount(getRecommendedAmount(), SavingsConstants.MANDATORY_AMOUNT_FOR_DEPOSIT_KEY, errors);
} else {
validateAmount(getRecommendedAmount(), SavingsConstants.RECOMMENDED_AMOUNT_FOR_DEPOSIT_KEY, errors);
}
}
validateCustomFields(request, errors);
} catch (PageExpiredException e) {
errors.add(SavingsConstants.MANDATORY, new ActionMessage(SavingsConstants.MANDATORY, mandatoryAmount));
}
}
}
if (!errors.isEmpty()) {
request.setAttribute(Globals.ERROR_KEY, errors);
request.setAttribute("methodCalled", method);
}
return errors;
}
Aggregations