use of org.springframework.binding.message.MessageContext in project head by mifos.
the class CustomerSearchFormBean method validateCustomerSearchStep.
/**
* validateXXXX is invoked on transition from state
*/
public void validateCustomerSearchStep(ValidationContext context) {
MessageContext messages = context.getMessageContext();
validator.validate(this, messages);
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class CustomizedTextFormBean method doValidation.
private void doValidation(ValidationContext context) {
MessageContext messages = context.getMessageContext();
validator.validate(this, messages);
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class UserFormBean method validateEnterUserDetailsStep.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION", justification = "should be the exception thrown by jodatime but not sure what it is right now.")
public void validateEnterUserDetailsStep(ValidationContext context) {
MessageContext messages = context.getMessageContext();
validator.validate(this, messages);
try {
this.dateOfBirth = new DateTime().withDate(this.dateOfBirthYear.intValue(), this.dateOfBirthMonth.intValue(), this.dateOfBirthDay.intValue());
} catch (Exception e) {
messages.addMessage(new MessageBuilder().error().source("dateOfBrith").code("NotValid.UserFormBean.dateOfBrith").defaultText("dateOfBirth is not valid").build());
}
try {
this.passwordExpirationDate = new DateTime().withDate(this.passwordExpirationDateYear.intValue(), this.passwordExpirationDateMonth.intValue(), this.passwordExpirationDateDay.intValue());
} catch (Exception e) {
messages.addMessage(new MessageBuilder().error().source("passwordExpirationDate").code("NotValid.UserFormBean.passwordExpirationDate").defaultText("Password expiration date is not valid").build());
}
try {
this.mfiJoiningDate = new DateTime().withDate(this.mfiJoiningDateYear.intValue(), this.mfiJoiningDateMonth.intValue(), this.mfiJoiningDateDay.intValue());
} catch (Exception e) {
messages.addMessage(new MessageBuilder().error().source("mfiJoiningDate").code("NotValid.UserFormBean.mfiJoiningDate").defaultText("mfiJoiningDate is not valid").build());
}
if (this.password.trim().isEmpty() || this.confirmedPassword.trim().isEmpty()) {
messages.addMessage(new MessageBuilder().error().source("password").code("NotEmpty.UserFormBean.password").defaultText("password is not correct.").build());
} else if (this.password.trim().length() < 6) {
messages.addMessage(new MessageBuilder().error().source("password").code("Min.UserFormBean.password").defaultText("password must have six characters at least.").build());
} else if (!this.password.equals(this.confirmedPassword)) {
messages.addMessage(new MessageBuilder().error().source("password").code("NotEqual.UserFormBean.password").defaultText("password is not correct.").build());
}
this.address.validate(messages, "UserFormBean");
// validate additional fields
for (CustomFieldDto additionalField : this.customFields) {
switch(additionalField.getFieldType().intValue()) {
case 0:
break;
case 1:
validateNumericField(messages, additionalField);
break;
case 2:
validateIfMandatoryField(messages, additionalField);
break;
case 3:
for (DateFieldBean dateFieldBean : this.customDateFields) {
if (dateFieldBean.getId().equals(additionalField.getFieldId())) {
validateAndBindDateField(messages, additionalField, dateFieldBean);
}
}
break;
default:
break;
}
}
if (messages.hasErrorMessages()) {
this.prepateForReEdit();
}
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class LoanRepaymentFormBean method validateEnterLoanRepaymentDetails.
public void validateEnterLoanRepaymentDetails(ValidationContext context) {
MessageContext messageContext = context.getMessageContext();
Errors errors = validator.checkConstraints(this);
if (errors.hasErrors()) {
for (FieldError fieldError : errors.getFieldErrors()) {
String arg = "";
if ("paymentAmount".equals(fieldError.getField())) {
arg = "Amount";
}
messageContext.addMessage(buildValidationMessage("errors.mandatory", fieldError.getField(), arg));
}
}
if (dateValidator == null) {
dateValidator = new DateValidator();
}
//payment date validation
if (!dateValidator.formsValidDate(paymentDateDD, paymentDateMM, paymentDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isAfter(new LocalDate())) {
messageContext.addMessage(buildValidationMessage("errors.futuredate", "paymentDate", "accounts.date_of_trxn"));
} else if (getPaymentDate().isBefore(lastPaymentDate)) {
messageContext.addMessage(buildValidationMessage("errors.payment.date.before.last.payment", "paymentDate", "accounts.date_of_trxn"));
}
//receipt date validation
if (isReceiptDateSpecified() && !dateValidator.formsValidDate(receiptDateDD, receiptDateMM, receiptDateYY)) {
messageContext.addMessage(buildValidationMessage("errors.invaliddate", "receiptDate", "accounts.receiptdate"));
}
//amount validation
if (paymentAmount != null && paymentAmount.doubleValue() <= 0) {
messageContext.addMessage(buildValidationMessage("error.penalty.incorrectDouble", "paymentAmount", "Amount"));
}
if (messageContext.hasErrorMessages()) {
this.truePrintReceipt = this.printReceipt;
this.printReceipt = false;
}
}
use of org.springframework.binding.message.MessageContext in project head by mifos.
the class LoanAccountFormBeanTest method shouldContainValidationMessageOnInterestRateFieldWhenInterestRateViolatesAllowedRange.
@Test
public void shouldContainValidationMessageOnInterestRateFieldWhenInterestRateViolatesAllowedRange() {
// setup
loanAccountFormBean.setInterestRate(200);
// exercise test
loanAccountFormBean.validateEnterAccountDetailsStep(context);
// verification
MessageContext messageContext = context.getMessageContext();
Message[] messages = messageContext.getAllMessages();
assertThat(messages.length, is(1));
Message message = messages[0];
assertThat(message.getSource().toString(), is("interestRate"));
assertThat(message.getText().toString(), containsString("loanAccountFormBean.InterestRate.invalid"));
}
Aggregations