bean-validation

Localization with bean validation in JSF

空扰寡人 提交于 2019-11-30 00:45:30
I made a MVC based website using JSF 2.0 and RichFaces 4. Every input text validation is been done using bean validation annotations. I am using Hibernate Validator as bean validation implementation. How can I display a localized message? If I use @NotNull(message="<h:outputText value=\"#{msg['Mymessage']}\" />") then it literally displays <h:outputText value="#{msg['Mymessage']}" /> as message. How is this caused and how can I solve it? You should and can not put JSF tags in the message. Also, JSF's own resource bundle won't be used to resolve localized validation messages. JSR303 bean

Java String Date Validation Using Hibernate API

此生再无相见时 提交于 2019-11-29 23:45:27
问题 I am attempting to validate String Date using javax.validation & Hibernate validation. i need to check given String date should be past and it should be correct yyyyMMdd format with all constraints like leap year, 30th , 31st day. public class UserInformation { @NotNull public String idNum = null; @NotNull //@Past @Pattern(regexp="\\d{4}(1[012]|0[1-9])(3[01]|[12]\\d|0[0-9])") public String dob= null; } I tried with this code but not working. Is there any solution. if we have custom validator

kotlin data class + bean validation jsr 303

谁都会走 提交于 2019-11-29 21:20:40
I'm trying to get Kotlin working with jsr 303 validation on a spring-data-rest project. Given the following data class declarartion : @Entity data class User( @Id @GeneratedValue(strategy = javax.persistence.GenerationType.AUTO) var id: Long? = null, @Size(min=5, max=15) val name: String ) The @Size annotation has no effect here, making me able to save a user with a name of 1 character. It works well when executing the very same example but in a Java class instead of Kotlin. This makes me think of a Kotlin problem. Thanks in advance for you help ! You need to use Annotation use-site targets

Binding JAX-RS bean validation error messages to the view

ⅰ亾dé卋堺 提交于 2019-11-29 15:07:05
问题 We can easily validate a JAX-RS resource class field or method parameter using bean validation something like the following: @Size(min = 18, max = 80, message = "Age must be between {min} and {max}.") String age; What is the easiest way to bind the error message to a JSP page? (Say, I am using Java EE 7 with Jersey or Resteasy) 回答1: EDIT 1 We introduced new annotation @ErrorTemplate in Jersey 2.3 that covers this use-case. Handling JAX-RS and Bean Validation Errors with MVC describes it

Hibernate validations on save (insert) only

混江龙づ霸主 提交于 2019-11-29 14:31:25
We encountered a problem with legacy code. There is a validation set for a "username" field, validating its length and making sure it contains at least one letter: @Column(name = "username") @Size(min = 4, max = 40) @Pattern(regexp = "^.*[a-zA-Z]+.*$") private String username; The problem we have is that some existing legacy data do not fit these validations, and I'm trying to find a way to make these validations to be ignored for legacy data (old users), while still be applied to newly created users. I was thinking about moving the validations to setUsername(...) method (so value will be

Validate elements of a String array with Java Bean Validation

纵然是瞬间 提交于 2019-11-29 14:19:02
I have a simple class that has one of its properties as a String array. As per this document, using @Valid on an array, collection etc. will recursively validate each element of the array/collection. @Valid @Pattern(regexp="^[_ A-Za-z0-9]+$") public String[] defaultAppAdminRoles; the above annotation on the property generates the following exception: Exception in thread "main" javax.validation.UnexpectedTypeException: No validator could be found for type java.lang.String[]. See: @Pattern at public java.lang.String[] com.hm.vigil.platform.ops.model.Application.defaultAppAdminRoles at org.apache

Custom bean validation does not `@inject` CDI beans and does not interpolate message?

谁都会走 提交于 2019-11-29 13:09:06
I am using GF4 with bean validation. I am trying to @Inject a service bean in my custom validator but I get a null value. public class TestValidator implements ConstraintValidator<>{ @Inject Service myService; } Isn't this suppose to be working with JEE7? Also, I am trying to find built-in dynamic message interpolation (Without writing my own MessageInterpolator ). I did see some examples but they are not very clear. What I am looking for is to pass dynamic parameters from the ConstraintValidator.isValid . For example: Message_test={value} is not valid And somehow weave this, in the same way

JSR 303 Bean Validation - Why on getter and not setter?

三世轮回 提交于 2019-11-29 10:46:29
问题 I don't understand why JSR 303 (bean validation) is for the getter methods and not setter? Isn't it more logical to put it under setter method since that is the entry point into a field and validation should be checked prior to that? 回答1: Annotating getters doesn't mean that validation is performed when a getter is invoked. It is just used to identify the property to which a constraint shall apply. The big advantage of putting constraints on (usually public) getters instead on (typically

Is there a standard way to enable JSR 303 Bean Validation using annotated method arguments

丶灬走出姿态 提交于 2019-11-29 08:23:16
问题 I've been looking a around for a while now with no luck. I'n not using Spring MVC but still want to use @javax.validation.Valid to enable validation of method arguments. To give an example public class EventServiceImpl implements IEventService { @Override public void invite(@Valid Event event, @Valid User user) { ... } } Using MVC, this is enabled for @Controller annotated beans with a simple <mvc:annotation-driven/> (see 5.7.4.3 Configuring a JSR-303 Validator for use by Spring MVC). Using

Multiple Regex @Pattern's for 1 Field?

爷,独闯天下 提交于 2019-11-29 07:59:57
问题 I was attempted to apply multiple @Pattern annotations to a single field: @Pattern(regexp = "(?=.*[0-9])", message = "Password must contain one digit.") @Pattern(regexp = "(?=.*[a-z])", message = "Password must contain one lowercase letter.") @Pattern(regexp = "(?=.*[A-Z])", message = "Password must contain one uppercase letter.") @Pattern(regexp = "(?=\S+$)", message = "Password must contain no whitespace.") private String password; However, I cannot do this. I want individual messages per