Questions tagged [bean-validation]

Bean Validation, previously commonly called just "JSR-303", is an annotation based validation framework for javabean properties and parameters of arbitrary methods. Hibernate Validator is the reference implementation and the most widely used one.

Online resources

1913 questions
0
votes
1 answer

How mix Spring Validator and JSR 303

I want to perform a validation both by using annotations and Spring Validator. Product.java public class Product { private int id; @NotNull(message = "cannot be null") private String desc; // getters and…
Couper
  • 414
  • 5
  • 13
0
votes
0 answers

Why my custom javax.faces.context.ExceptionHandler doesn't handle javax.validation.ConstraintViolationException

My custom exception handler is not being invoked by the container to intercept (checked or unchecked) exceptions (I verified it through the debugger). I have this Entity bean class with @Email annotation for the email field, and when the user types…
Darvin
  • 148
  • 8
0
votes
1 answer

Restrict users to create data only for themselves

I have a microservices architecture deployed on kubernetes with istio gateway, AWS cognito used for Authentication. Now when the user logs in to the APP, he can create/view data using the API's. The mobile FE application sends the "userId" of the…
Raghav
  • 552
  • 1
  • 9
  • 34
0
votes
1 answer

Wildfly 21 – how to customize returns for Bean Validation exceptions

I've tried registering custom exception mappers in multiple ways: @Provider public class ConstraintViolationMapper implements ExceptionMapper { @Override public Response toResponse(ConstraintViolationException…
ftr
  • 2,105
  • 16
  • 29
0
votes
1 answer

How to do custom validation on entity for multitenant setup using Spring + Hibernate

I am trying to validate a field of an Entity using custom ConstraintValidator implementation in a multi-tenancy setup using spring hibernate. How do we make the custom validator tenant aware? The entity manager and other autowired beans in the…
Guru
  • 2,739
  • 1
  • 25
  • 27
0
votes
1 answer

validate bean constraint on manufacturer property sometimes based on configuration from data base

Can we achieve @NotNull constraint gets executed only if it is enabled to execute in DB public class Vehicle { @NotNull //supposed to execute only if configuration in database is enable to execute this @Notnull annotation private String…
0
votes
1 answer

Validation issue with javax constraint

In a spring boot application, I have an entity where I put some annotation validation. @Max(value = 17) private String currency; @Max(value = 1) private String freq; @Max(value = 2) private String compliance; @Max(value = 1) private String…
robert trudel
  • 5,283
  • 17
  • 72
  • 124
0
votes
1 answer

What is the best way to validate the same bean for multiple use cases in java/spring?

TL;DR: From the "clean code" point of view, what is the best way to implement validation for any object for different use cases? To clarify, suppose I have this entity: public class User { private Integer id; private String…
user9398992
0
votes
1 answer

Create runtime constraints and validate a map of fields

I have a map of input fields that I would like to validate using JSR-303 by creating dynamic constraints at runtime. Let's say the structure of my map looks like: name: Foo description: Foo description Now, if I have a set of rules stored in some…
adarshr
  • 61,315
  • 23
  • 138
  • 167
0
votes
0 answers

Error after migration omnifaces 3.7.1 to 3.8.1 validateBean with UIComponent

I'm recently migrate my jsf webapp to omnifaces 3.8.1 and i'm getting an error on validateBean. This seams to be caused by UIComponent property in bean. 11:10:18,385 ERROR [io.undertow.request] (default task-9) UT005023: Exception handling request…
Dani
  • 1
  • 1
0
votes
1 answer

Is there a way to get an instance of EntityManager injected in a custom bean validator when executing a @WebMvcTest with Spring Boot?

I have created a custom bean validator as follows: public class UniqueValidator implements ConstraintValidator { private final EntityManager entityManager; private Class entityClass; private String entityField; …
0
votes
1 answer

Why 500 error return json message value is empty

Spring boot app there is a method like below getBasicInfoList(@RequestParam int pageNum, @RequestParam @Max(20)int pageSize) pageSize cannot be more than 20, and if more than 20, got below return { "timestamp": 1602562522208, "status": 500, …
zhuguowei
  • 8,401
  • 16
  • 70
  • 106
0
votes
1 answer

Validating proxied Java Beans doesn't compare against correct values

I'm trying to make a CDI extension which will validate a Java object which is bound to configuration values. public class ExampleConfig { @Range(min = 1000, max = 9999) private int value; @Inject public…
Seth Falco
  • 313
  • 6
  • 22
0
votes
1 answer

Seam Hibernate Validator displaying JSF messages

I have an application that uses Seam 2.2.2- JSF 1.1 - Hibernate Validator 3.1.0.GA. I am trying to display custom messages using hibernate validate message=() option. message=() gets displayed for other validators like @Length. But the message I set…
user238021
  • 1,181
  • 8
  • 30
  • 44
0
votes
1 answer

Allow to override/set constraints validation for a child object for Hibernate validation

I have the following class : class ContactInformation { String phone; String email; } which is used in the following classes : class Person { @Valid ContactInformation contactInformation; } class Station { @Valid …
Teocali
  • 2,725
  • 2
  • 23
  • 39