Displaying entity level error messages in thymeleaf - spring-boot

I have written a custom annotation and placed the annotation on the entity level.
#ValidConfirmPassword
public class User {...}
The custom validator is returning the invalid message, but, I am not able to display the message on the UI.
How should I display the error messsage specific to the entity using Thymeleaf?

Related

Custom Exception Handling in Spring Boot with JSP

I am new to Spring Boot with JSP development and I am a bit lost when it comes to handling exceptions.
This is my scenario:
User clicks on a User from the JSP
Through a path variable I retrieve user id.
I then pass the user id to a service class.
The service class will query for the user by connecting with the JPARepository
The place where I am confused is this.
If the returned object is a null, should I return that null object or should I throw a custom exception like ResourceNotFoundException and then have catch statements in the controller methods?
Please. Any help would be highly appreciated.

Customize spring boot validation message from database

I am using spring validation to validate the Rest Controller input, I would appreciate if any one can tell me is there a possibility of throwing custom message in case of exception and the custom message should come from database rather than from a properties file.
You can achieve this by setting a custom validation message source on Spring's LocalValidatorFactoryBean.
Your message source needs to implement the MessageSource interface and read its messages from the database.
Reference:
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.html#setValidationMessageSource-org.springframework.context.MessageSource-
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/MessageSource.html

Freemarker missing spring message

I am loading asynchronously (Ajax call to Spring MVC Controller) a free marker template. But i get error message complaining about missing message property.
This is my Spring controller method
#RequestMapping('/messages/{messageId}')
public String conversation(#PathVariable('messageId') Long messageId, ModelMap model) {
//BUILD CONVERSATION MODEL model.put....
"async/conversation"
}
async/conversation.ftl
.....<#spring.message "user.conversation.title"/>.....
I have message properties with
user.conversation.title Conversation
This message is working just fine in other scenario, i think there is some issue loading the template asynchronously.
Solved: I had forgotten to make an import.
<#import "/spring.ftl" as spring/>

Spring webflow validator with no error message

I have spring webflow applicaiton, which has a contact info page and while submitting the form, it goes to spring validator.
And executing validations, if any wrong data then we adding a error message to validationcontext. Using ${errorMessags} we list the error messages.
But I have a scenario where I need to show a warning message to user in middle of page.
Either through spring validation or spring flowscope variable in Spring Validator
Is there any way to do it?
Thanks in Advance!!!
Why do you want to do that on validator? Do you want to show that warning in next view?
I guess you could set message in or in to flashScope variable and show it on next page.

Spring validation in multiple forms

Can we display error messages in one jsp but in 2 different forms.I am validating my bean using spring validation.Its working fine but if there is an error in the binding results then I am able to display the error message in the form from where action is executed but not in the other resultant form.
is the error tag in spring validation is mapped to jsp form from where that action is called.
Your BindingResults is just an object, which you can put in your Model and use on the page however you want. You may need to put it into Session if you plan to use it on a separate form.

Resources