bean-validation

Can I change the property path in a ConstraintValidator for Method arguments?

社会主义新天地 提交于 2019-11-27 17:16:47
问题 If you are familiar with the Bean Validation Framework you know that you cannot get the name of a method argument. So if you do a @NotNull constraint on the first argument of a method and the validation fails the getPropertyPath will be something like "arg1". I would like to create my own version of @NotNull that can take a value e.g. @NamedNotNull( "emailAddress" ). But I can't figure out how to override the #getPropertyPath in my Validator? Is there any way to do this or am I stuck with

In Hibernate Validator 4.1+, what is the difference between @NotNull, @NotEmpty, and @NotBlank?

感情迁移 提交于 2019-11-27 16:39:49
I can't seem to be able to find a summary that distinguishes the difference between these three annotations. @NotNull : The CharSequence, Collection, Map or Array object is not null , but can be empty. @NotEmpty : The CharSequence, Collection, Map or Array object is not null and size > 0 . @NotBlank : The string is not null and the trimmed length is greater than zero . To help you understand, let's look into how these constraints are defined and carried out (I'm using version 4.1): The @NotNull constraint is defined as: @Constraint(validatedBy = {NotNullValidator.class}) This class has an

Hibernate @OneToOne @NotNull

混江龙づ霸主 提交于 2019-11-27 14:48:44
问题 Is it valid to declare @OneToOne and @NotNull on both sides of a relationship, such as: class ChangeEntry { @OneToOne(cascade=CascadeType.ALL) @NotNull ChangeEntryDetails changeEntryDetails; public void addDetails(ChangeEntryDetails details) { this.changeEntryDetails = details; details.setChangeEntry(this); } } class ChangeEntryDetails { @OneToOne(cascase=CascadeType.ALL) @NotNull ChangeEntry changeEntry; public void setChangeEntry(ChangeEntry changeEntry) { this.changeEntry = changeEntry; }

How to I get Spring-Data-MongoDB to validate my objects?

好久不见. 提交于 2019-11-27 14:02:21
I have a very simple Spring Boot application that uses Spring-Data-Mongodb All I want to do is set a JSR-303 validation rule that says the object I'm saving must have a username. I read that JSR-303 was added to spring-data-mongodb in version 1.1 so I assumed that when I save an object it's validated but this isn't the case. Does anyone have a simple example setup that shows how this works? My User pojo looks like public class User { @Id private String id; @NotNull(message = "User Name is compulsory") private String userName; private String password; public User() {} public String getId() {

JSR 303: How to Validate a Collection of annotated objects?

ぐ巨炮叔叔 提交于 2019-11-27 13:25:24
问题 Is it possible to validate a collection of objects in JSR 303 - Jave Bean Validation where the collection itself does not have any annotations but the elements contained within do? For example, is it possible for this to result in a constraint violation due to a null name on the second person: List<Person> people = new ArrayList<Person>(); people.add(new Person("dave")); people.add(new Person(null)); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set

what to use, managed beans (backing beans) or entity beans?

懵懂的女人 提交于 2019-11-27 12:53:01
I see a lot of examples marking beans as entity beans (@Entity) & named beans (CDI), so as to avoid creating 2 classes (managed bean & entity bean) and also to make use of Bean Validation so that validation can be performed on both client & server. So should I be using a single class or not, are there any issues or should I be having my managed beans or service layer create entity beans using the data from managed beans ? Arjan Tijms The @Named or @ManagedBean annotations are typically used to let the bean container (CDI/JSF) create an instance of a bean on demand when referenced by expression

javax.validation.ValidationException: Unable to find default provider

十年热恋 提交于 2019-11-27 12:00:47
问题 I am currently working on Spring MVC web app and trying to hook up validation using the @Valid annotation. When I fire up the application I'm getting the following exception: javax.validation.ValidationException: Unable to find a default provider I have Hibernate Validator 3.1.0.GA on the classpath as well as javax validation 1.0.0.GA, Hibernate Core 3.3.1.GA and Hibernate Annotations 3.4.0.GA. Is there an incompatiblity in those versions that I'm not seeing, or can anyone think of any reason

JSF 2.0: How to skip JSR-303 bean validation?

此生再无相见时 提交于 2019-11-27 11:59:44
问题 How to skip JSR-303 Bean validation with JSF, when a button is clicked? A bit lengthy question to explain a few approaches... Consider a list in a form: <h:form id="form"> <h:commandButton value="Add row"> <f:ajax execute="foo" listener="#{bean.add()}" render="foo" /> </h:commandButton> <h:dataTable id="foo" var="foo" value="#{bean.foos}"> <h:column> Name: <h:inputText id="field" value="#{foo.name}" required="true" /> <h:messages for="field" /> </h:column> <h:column> <h:commandButton value=

Validate class level bean validation constraints in JSF

和自甴很熟 提交于 2019-11-27 09:47:45
It seems that JSF 2.0 does not call "class level constraints". Quoting from an SO answer JSF 2.0 doesn't call class level validation constraints. From JSF validation: JSF 2 provides built-in integration with JSR-303 constraints. When you are using bean validation in your application, JSF automatically uses the constraints for beans that are referenced by UIInput values. The answer furthermore suggests using SeamFaces to validate the class-level constraints anyways. Unfortunately this is a non-option, since it introduces a somewhat massive dependency for just validating what should be validated

How to disable Hibernate validation in a Spring Boot project

依然范特西╮ 提交于 2019-11-27 08:35:34
I have a spring boot project that has a CrudRepository, an Entity and a Controller. I am basically trying to persist an entity based on the data passed to the Controller. To do this, I am using spring-boot-starter-jpa . My Entity is annotated with JSR-303 annotations, which are checked in the controller before the data gets passed to the CrudRepository for persistence. Controller method: @RequestMapping(value = "users", method = { RequestMethod.POST }) public SuccessfulResponse<User> addUser(@Valid @RequestBody User user, BindingResult validation) { if (validation.hasErrors()) { throw new