• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

What is the propertyNode of ConstraintValidatorContext?  RSS feed

 
Ranch Hand
Posts: 37
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have this code:


According to the api the addPropertyNode method “Adds a property node to the path the ConstraintViolation will be associated to.
name describes a single property. In particular, dot (.) is not allowed.”

But whatever this value is, it still reads the my.custom.message from ViolationMessages.properties. So, what does this do? When should I use it?

Thanks in advance.
 
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A constraint violation has a message (and template), but also a path to the property that did not pass validation.

In your example, you specify the message template, which leads to the message being loaded from ViolationMessages.properties. The property node takes the current property path (for the root object that's empty), and appends something to it. Those are two different attributes of the constraint violation.
 
Christian Wansart
Ranch Hand
Posts: 37
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, but where does the property path come into account?

It doesn't matter if I add any propertyNode, in this example it will still read the message from the ViolationMessages.property with the property name "my.custom.message".

I don't understand where the propertyNode does anything other than set a value. Where is it used?
 
Rob Spoor
Sheriff
Posts: 21503
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use it to report where in a request a constraint violation occurred. If you have one class with four String properties all annotated with @NotEmpty, and one of them is null, it's the property path that you can use which of the four properties is the actual empty one.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!