Vojislav Kovacevic

+ Follow
since Apr 25, 2019
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vojislav Kovacevic

I want to compare 2 passwords to see if they match, I can do that with a field and `@AssertTrue`, however I cannot display the message if validation fails.

I am trying like so:

And in the view:

Using breakpoints, I can see that all values are correct as expected, however I **always** get the error message, even if the passwords match.

It seems that the `passFlag` does not change its value for validation even with `@AssertTrue` being true (because when I use breakpoints to see the values I can see that the `passFlag` has correct value, but I **still** get the error message).

So how can I modify the above code to work with the error message, and even better - is there a better to compare the 2 fields and display an error message if need be?
2 years ago
I want to compare 2 passwords to see if they match, and if they don't I want to display a validation message.

I can get them to compare correctly, however I cannot get the validation message to display.

The way I did it in SpringBoot 2.1.3 is: (now I am using 2.1.6 and it does not work)

The above code works as expected, using breakoints I can see that all values are correct, however it always returns as "not validated", even if the passwords match.

I guess the above code does not work anymore for some reason, so is there another way to display an @AssertTrue message in thymeleaf if validation fails?
2 years ago
SpringBoot 2.1.6

I have a class like so:

However it seems it is being ignored, it is not scanned I'd say. It's in the same package as the main Application file.

I've used this @ControllerAdvice in another project and it worked fine, but now for some reason it is simply being ignored, any ideas?

SORRY, there was an issue with the template files NOT with @ControllerAdvice, this topic should be deleted.
2 years ago
I have 2 user roles - user and admin , if I go to a url where any authentication is needed and I am not authenticated - I get redirected to the login page, which is fine.

However, if I am logged in as user, and I try to access an admin only page, I get the home page displayed, but the url stays the same. I want to actually redirect to the home page rather than just display it.

So is there any way to make the accessDeniedPage method redirect, because as I said the home page is displayed but the url does not change.
2 years ago
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!
2 years ago
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.
2 years ago
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?
2 years ago
I am using @ControllerAdvice to use shared data accross my application.

It all worked fine until I did an ajax request.

The problem is that the relevant data from @ControllerAdvice is always a step behind.

This is the relevant code from @ControllerAdvice

And my view:

Now, If I use the application normally without ajax, meaning if let's say I add an item to the cart and the page refreshes normally, then it all works as expected, I get the correct values for csize and ctotal, however if I use ajax to hit the appropriate url and then return the view, the csize and ctotal variables are always a step behind, so for example if there are no items added and I add the first item, I don't see a difference via ajax, and then if I add another then the value of csize is 1 (instead of 2), then if I add another it is 2 instead of 3 and so on. But if I refresh the page it is correct.

So basically via ajax the data from @ControllerAdvice is a step behind, any idea why? I mean I basically get "why", because I guess only an html view is returned and there is no real redirect, but can I still achieve proper values somehow?
2 years ago
Hi Stephen,

It's just the logic I went with on the fly.

The ids are there as keys to separate each product (which is what the Cart class contains).

I will think about what you said and try to implement it and see if it's a better solution.

I am always open to better code!
2 years ago
Any way to get rid of unchecked warning when I do this?

I am using @SuppressWarnings("unchecked"), is there a better option in your opinion?
2 years ago
I am saving a HashMap into a session like so:


But how am I supposed to get it out of the session back into a HashMap ?

I am aware that the session data is stored as an object but do not know how to get it into a `HashMap`

I've tried:


But it says

cannot from Object to HashMap

2 years ago
First of all for what it's worth, out of few forums you are the only one that helped me with the correct suggestions, so thanks a lot!

What doesn't work? Do you still get 404 errors?

It all works now, I meant before I set the path.

All static files that already exist (images, css, js) are rendered as is, without needing to specify the path, so why doesn't this apply straight after storing data (uploading the image in my case) as well?

Basically if I just want to just get static data (images, css, js) I don't need to set paths, but if I want to upload files and view them as soon as I upload them then for some reason I need to set the paths for that, why?
2 years ago
OK I finally did it like so:

So is this a must because I am developing locally, and also if I deployed this application, would it be enough to just get rid of this code or would I need to actually modify it so that it works as expected online as well?

Also, why doesn't it work upon redirect (as soon as the image is uploaded), but if I refresh the page after uploading or just go the page before uploading it does work?
2 years ago