Good, I would like to internationalize a variable in a controller. I have a form in which I fill some data and depending on the data I enter in the form I want to give value to a property of the entity that I show the form. I put you in situation, I have a form of an entity that is applicationFor (request) in which the client can put a credit card and if it is expired would insert the property reasonWhy "your card has been canceled" but in a way internationalized.
Controller that receives the submit of the form.
@RequestMapping(value = "/enter", method = RequestMethod.POST, params = "enter")
public ModelAndView enter(@Valid ApplicationFor applicationFor, BindingResult binding) {
ModelAndView result;
if (binding.hasErrors())
result = this.createEditModelAndViewCreditCard(applicationFor, null);
else
try {
this.applicationForService.enter(applicationFor);
result = new ModelAndView("redirect:list.do");
} catch (final Throwable oops) {
result = this.createEditModelAndViewCreditCard(applicationFor, "applicationforcreditError.commit.error");
}
return result;
}
Here the service that answers the request that is where I check the credit card and put in the property reasonWhy what I would like to internationalize:
public ApplicationFor enter(final ApplicationFor applicationFor) {
Assert.notNull(applicationFor);
Assert.isTrue(applicationFor.getStatus().equals("DUE"));
ApplicationFor result;
if (this.checkCreditCard(applicationFor.getCreditCard())) {
applicationFor.setStatus("ACCEPTED");
applicationFor.setReasonWhy("");
} else {
applicationFor.setStatus("REJECTED");
applicationFor.setReasonWhy("Your credit card is expired");
}
result = this.applicationForRepository.save(applicationFor);
return result;
}