
Originally Posted by
Marten Deinum
Why? That is already handled by the framework, simply set the error code and the message will be resolved for you...
i am using a non-standard message code that's why I am looking for other way that allowing me to pass the code then return back the message.
i injected the messageSource inside my validator in order to have access with my resourceBundle...
messages.properties
Code:
EMCC00001=Item1 is required
EVY100001=Item2 is required
validator
Code:
@Component
public class RosenkaSanshutsuViewValidator {
@Autowired
private MessageSource messageSource;
private MessageSourceAccessor accessor;
/**
* @param messageSource the messageSource to set
*/
public void setMessageSource(MessageSource messageSource) {
this.accessor = new MessageSourceAccessor(messageSource);
}
public void validateEnterRosenka (RosenkaSanshutsuView view, ValidationContext context) {
MessageContext messages = context.getMessageContext();
messages.addMessage(new MessageBuilder().error().source("selectedTaishoHaniSentei.analyzeId").defaultText(DEFAULT_MESSAGE).build());
}
}
domain
Code:
public class RosenkaSanshutsuView extends AbstractComplex {
private SelectedTaishoHaniSentei selectedTaishoHaniSentei = new SelectedTaishoHaniSentei();
/**
* @param selectedTaishoHaniSentei the selectedTaishoHaniSentei to set
*/
public void setSelectedTaishoHaniSentei(SelectedTaishoHaniSentei selectedTaishoHaniSentei) {
this.selectedTaishoHaniSentei = selectedTaishoHaniSentei;
}
/**
* @return the selectedTaishoHaniSentei
*/
public SelectedTaishoHaniSentei getSelectedTaishoHaniSentei() {
return selectedTaishoHaniSentei;
}
}
public class SelectedTaishoHaniSentei extends AbstractComplex {
private String analyzeId = "";
private String joruiNo = "";
/**
* @return the analyzeId
*/
public String getAnalyzeId() {
return analyzeId;
}
/**
* @param analyzeId the analyzeId to set
*/
public void setAnalyzeId(String analyzeId) {
this.analyzeId = analyzeId;
}
/**
* @return the joruiNo
*/
public String getJoruiNo() {
return joruiNo;
}
/**
* @param joruiNo the joruiNo to set
*/
public void setJoruiNo(String joruiNo) {
this.joruiNo = joruiNo;
}
}