bean-validation

Bean Validation with Extra Information

强颜欢笑 提交于 2019-12-01 19:17:02
I am trying to create a UniqueName annotation as a cutomize bean validation annotation for a create project api: @PostMapping("/users/{userId}/projects") public ResponseEntity createNewProject(@PathVariable("userId") String userId, @RequestBody @Valid ProjectParam projectParam) { User projectOwner = userRepository.ofId(userId).orElseThrow(ResourceNotFoundException::new); Project project = new Project( IdGenerator.nextId(), userId, projectParam.getName(), projectParam.getDescription() ); ... } @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) class ProjectParam { @NotBlank

Bean validation not working if name variable is prefixed with underscore

孤者浪人 提交于 2019-12-01 18:53:27
问题 I'm trying out some bean validation and I'm stumbling upon 'strange' behavior. I'm working with Glassfish and Primefaces as a front-end (if it makes any difference). Elsewhere in my project I use the Hibernate-validator, I'm not sure if it is validating JSF (else it is the default in Glassfish). I have a managed bean: @javax.faces.bean.ManagedBean @javax.faces.bean.ViewScoped public class TestBean { @Size(min=8) private String _testString; public String getTestString() { return _testString; }

How can I skip bean validation if all fields for the entity are empty?

妖精的绣舞 提交于 2019-12-01 18:26:15
I have a address entity like this: @Entity public class Address implements java.io.Serializable { @Id @GeneratedValue(strategy = IDENTITY) private Long id; @Size(max = 100) private String street; @Size(max = 15) private String nr; @Field @Size(min = 1, max = 20) @NotBlank private String city; } This is part of several other entities. For one such entity the address is optional. I have a view where our users can edit the whole entity via several form inputs, including several address fields. To be able to edit the address, I initialize the parent entity with an empty address entity. Now the

Resteasy Bean Validation Not Being Invoked

十年热恋 提交于 2019-12-01 17:43:16
Problem Background I have a Resteasy service that uses Spring through Resteasy's SpringContextLoaderListener . This is built on Resteasy version 3.0-beta-6 . I would like to use bean validation on the incoming requests, but I can not get Resteasy to call the validator. It acts like there is no validation configured and simply passes the method the invalid input object. Question How do I enable bean validation in Resteasy? What I've Tried I have done the following: Annotated my resource class with @ValidateRequest Annotated the method parameter with @Valid Annotated the constraints on my input

Java Bean Validation: How do I specify multiple validation constraints of the same type but with different groups?

吃可爱长大的小学妹 提交于 2019-12-01 16:20:26
I have multiple processes in which the bean properties must have different values. Example: @Min( value=0, groups=ProcessA.class ) @Min( value=20, groups=ProcessB.class ) private int temperature; Unfortunately the bean validation JSR 303 has not set @Repeatable on javax.validation.constraints.Min so this approach does not work. I found "Min.List" but without any doc about how to use it. Instead the official Oracle doc states at http://docs.oracle.com/javaee/7/api/javax/validation/constraints/class-use/Min.List.html No usage of javax.validation.constraints.Min.List So at moment this looks like

Resteasy Bean Validation Not Being Invoked

冷暖自知 提交于 2019-12-01 15:49:03
问题 Problem Background I have a Resteasy service that uses Spring through Resteasy's SpringContextLoaderListener . This is built on Resteasy version 3.0-beta-6 . I would like to use bean validation on the incoming requests, but I can not get Resteasy to call the validator. It acts like there is no validation configured and simply passes the method the invalid input object. Question How do I enable bean validation in Resteasy? What I've Tried I have done the following: Annotated my resource class

How to localize Bean Validation messages

孤者浪人 提交于 2019-12-01 15:38:30
问题 I have a class and using annotation to validate the class properties. My web page (jsf2.2/primefaces/maven) is multilanguage (DE-utch, FR-rench, IT-alian). My problem is that the hibernate-validator has support for some languages(de, en, es, fr, hu, tr, pt_BR, mn_MN, zn_CN) but not Italian! (listed in the jar, org->hibernate->validator) So when i use the Italian version of my web page the validation messages are shown in english(default choice of hibernate). How i can override this, and

How does it work with bean validation messages and i18n in JSF2?

谁都会走 提交于 2019-12-01 15:25:11
问题 I created validation messages(ValidationMessages.properties) file to make the i18n possible in my project. It looks like: pwtNumber.error=PWT Number error.. I defined it in faces-config.xml: <message-bundle>com.mycompany.web.i18n.ValidationMessages</message-bundle> In my code I used it in this way: @Null(message = "{pwtNumber.error}") public String getPwtNummer() { return pwtNummer; } But the problem is i don't get the error message but the key from the properties file. It is the error

Cross field bean validation - why you no work

筅森魡賤 提交于 2019-12-01 14:41:47
I've got a little problem here with my application. I'd like to check if fields password and confirm password match together, so I tried to do it like in the first answer for this question: Cross field validation with Hibernate Validator (JSR 303) The problem is that it actually doesn't work and I HAVE NO IDEA WHY. Please, help me! This is my first post here, so please don't be too harsh for me. Here's my Annotation : /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package pl.lodz.p.zsk.ssbd2012.ssbd12.ValidationConstraints; import java.lang

How to validate a List<BigDecimal> with @DecimalMin and @DecimalMax?

心已入冬 提交于 2019-12-01 13:16:31
In my Spring project I have a POJO class with a property for a CMYK color. I want this property to be represented by a JSON array with exactly 4 floating-point numbers. Each number must be in the range between 0.0 and 1.0 . Currently I'm struggling with the validation of this property. I have researched already and found that the @DecimalMin and @DecimalMax annotations cannot be used on Float or float (see the answers to this question ). Therefore I already abandoned List<Float> and use List<BigDecimal> instead. Here is my stripped down POJO class: public class Settings { @NotNull @Size(min =