• 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
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

How to connect @transient and @assertTrue field error message to form input with thymeleaft  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a registration form which works fine (both the validation and persisting to the database).

However, I have a problem displaying a message for the "confirm password" field.

In my Entity class, I have a field marked with @Transient, because I don't want that field to represent a table column, and then I use @AssertTrue to validate that it matches the password field.



That works fine in the sense that the form does not pass validation if both passwords don't match, and also if I loop through the errors in my html file like so:



I do see the correct message (e.g. "Passwords must match").

But I also have the error messages displaying below each form input, like so:



But since confirmPassword does not have validation applied to it, how can I make it so that it displays like for example for the password field?

I tried something like this which of course didn't work:



what do I need to use instead of confirmPassword in this line



to make it display the error message?
 
Saloon Keeper
Posts: 10136
214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you use for your password confirmation field instead?
 
Vojislav Kovacevic
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing, password is its own field and also form input.

And for some reason, if the passwords do not match, I get the error when I iterate through all the errors which is fine, but if they do match, I just realized that I get an exception for some reason - List of constraint violations:[ ConstraintViolationImpl{interpolatedMessage='Passwords must match'

So if they don't match, I get an error n my html file which is fine and correct (just not at the right place), but if they do match I get an exception.

Maybe I am going about checking if both fields match in the wrong way.
 
Vojislav Kovacevic
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it but it's kind of messy.

First of all, for some weird reason (weird to me at least), the following does not work even if I know for a fact the 2 fields have the same string.



So because the above doesn't work for some reason (by "doesn't work" I mean it doesn't return true when it should), I added another @Transitional field as a flag and rewrote the above like so:



At this point it does return true / false as it should.

And to also display the message below the form input, I added another @Transitional field with validation, and modified the above code:






Now it seems to be working as expected, but if there is a better (shorther) way of doing the same thing I'd much appreciate it!
 
straws are for suckers. tiny ads are for attractive people.
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!