Hello,
if an error occurs, im getting error message "home.Error.BadInput.CountryCode". All other string are working well.
My error messages AND other strings are defined in my lang_de.properties or lang_en.properties files.
what im doing wrong?
P.S. im using my own Validator (ConstraintValidator). I dont need to use Hibernatevalidators
Code:@Target({ ElementType.METHOD, ElementType.FIELD }) @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = CountryCodeValidator.class) public @interface CountryCodeContraint { String message() default "home.Error.BadInput.CountryCode"; Class<?>[] groups() default {}; Class<? extends Payload>[] payload() default {}; }
My Controller:Code:public class CountryCodeValidator implements ConstraintValidator<CountryCodeContraint, String> { public void initialize(CountryCodeContraint constraintAnnotation) { // } public boolean isValid(String value, ConstraintValidatorContext context) { if(value == null || value.isEmpty() || value.length() != 3){ return false; } return true; } }
And finally .jspCode:... @RequestMapping(method = RequestMethod.POST) public String search(@Valid SearchInput input, BindingResult brResult, HttpSession session) { logger.info("SEARCH: " + input); if (brResult.hasErrors()) { logger.info("\tFEHLER"); return Page.HOME.file; } return Page.SEARCH_RESULT.file; } ...
Code:<form:form method="POST" id="searchbox" modelAttribute="<%=Attributes.SEARCH_INPUT %>"> <div onclick="hideOrShowLangs()" id="countrySel"><fmt:message key="<%=LANG %>"/></div> <form:input path="code" value="<%=LANG %>" style="display: none;"/> <form:errors path="code" cssClass="error"/> <form:input id="search" path="term" name="location" placeholder="${plcHolder }"></form:input> <form:errors path="term" cssClass="error" /> <input id="submit" type="submit" value="<fmt:message key="home.Input.Search"/>"/> </form:form>


Reply With Quote