JSP Method not found: class java.lang.String - java

I have this exception andd i can't find a solution
COntroller :
#RequestMapping(value="/sujet")
public String detail(Model model, HttpServletRequest request, Long idSujet) {
Utilisateur user = (Utilisateur) request.getSession().getAttribute("user");
model.addAttribute("nbrMails", metierUtilisateur.listDesEmailsRecuNonLu(user.getIdUtilisateur()).size());
SujetForum sujet = metierSujetForum.findById(idSujet);
sujet.setMessagesForums(metierSujetForum.getListMessageForum(idSujet));
model.addAttribute("sujet", sujet);
model.addAttribute("messages", metierSujetForum.getListMessageForum(idSujet));
return "/coordinateur/detailSujetForum";
}
this is my Bean definition :
i defined all the getters and setters for all attributes but is till get the same exception
#Entity
public class MessagesForum implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idMessage;
private String message;
private Date dateDepotMessage;
private boolean messageCorrecte;
#ManyToOne
#JoinColumn(name = "idSujet")
private SujetForum sujetForum;
#ManyToOne
#JoinColumn(name = "idUtilisateur")
private Utilisateur utilisateur;
#OneToMany(mappedBy = "messageForum")
private Collection<PieceJointeForum> pieceJointeForums;
public MessagesForum(String message, Date dateDepotMessage, boolean messageCorrecte) {
super();
this.message = message;
this.dateDepotMessage = dateDepotMessage;
this.messageCorrecte = messageCorrecte;
}
public MessagesForum() {
super();
}
public Long getIdMessage() {
return idMessage;
}
public void setIdMessage(Long idMessage) {
this.idMessage = idMessage;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Date getDateDepotMessage() {
return dateDepotMessage;
}
public void setDateDepotMessage(Date dateDepotMessage) {
this.dateDepotMessage = dateDepotMessage;
}
public boolean isMessageCorrecte() {
return messageCorrecte;
}
public void setMessageCorrecte(boolean messageCorrecte) {
this.messageCorrecte = messageCorrecte;
}
public SujetForum getSujetForum() {
return sujetForum;
}
public void setSujetForum(SujetForum sujetForum) {
this.sujetForum = sujetForum;
}
public Utilisateur getUtilisateur() {
return utilisateur;
}
public void setUtilisateur(Utilisateur utilisateur) {
this.utilisateur = utilisateur;
}
public Collection<PieceJointeForum> getPieceJointeForums() {
return pieceJointeForums;
}
public void setPieceJointeForums(Collection<PieceJointeForum> pieceJointeForums) {
this.pieceJointeForums = pieceJointeForums;
}
}
this is the output of the exception
615: <div class="media-body">
616: <div class="media-text">
617: <h5 class="semibold mt0 mb5 text-accent"></h5>
618: <p class="mb5">${msg.getIdMessage() }.</p>
619: <!-- meta icon -->
620: <p class="mb0">
621: <span class="media-meta"></span> <span class="mr5 ml5 text-muted">*</span> <a href="javascript:void(0);" class="media-meta text-default" data-t
oggle="tooltip" title="" data-original-title="Reply"><i class="ico-reply"></i></a>
Stacktrace:] with root cause
javax.el.MethodNotFoundException: Method not found: class java.lang.String.getIdMessage()
at javax.el.Util.findWrapper(Util.java:352)
at javax.el.Util.findMethod(Util.java:214)
at javax.el.BeanELResolver.invoke(BeanELResolver.java:174)
at org.apache.jasper.el.JasperELResolver.invoke(JasperELResolver.java:139)
at org.apache.el.parser.AstValue.getValue(AstValue.java:173)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:967)
at org.apache.jsp.WEB_002dINF.views.coordinateur.detailSujetForum_jsp._jspx_meth_c_005fforEach_005f0(detailSujetForum_jsp.java:1242)
at org.apache.jsp.WEB_002dINF.views.coordinateur.detailSujetForum_jsp._jspService(detailSujetForum_jsp.java:832)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

<c:forEach items="=${messages }" var="msg">
<div class="media-list media-list-bubble">
<div class="media">
<a href="javascript:void(0);" class="media-object pull-left"> <img src="" class="img-circle" alt="">
</a>
<div class="media-body">
<div class="media-text">
<h5 class="semibold mt0 mb5 text-accent"></h5>
<p class="mb5">${msg.idMessage }.</p>
<!-- meta icon -->
<p class="mb0">
<span class="media-meta"></span> <span class="mr5 ml5 text-muted">*</span> <i class="ico-reply"></i>
</p>
<!--/ meta icon -->
</div>
</div>
</div>
</div>
</c:forEach>

msg in JSP here seems to be coming as String and You are expecting your bean Class type .
After you get the bean also
${msg.getIdMessage() }.
This seems to be issue in your JSP. just try with
${msg.idMessage() }.

send me your jsp and don't call with get method u should call directly with property values. like amit.rk3 said. and where you are using this msg in your jsp
use like this
<c:forEach var="msg" items="${messages}">

Related

Access Multiple beans using thymeleaf and springboot MVC

Trying to access multiple objects in the POST method using SpringBoot MVC and thymeleaf.
here is the controller.
#Controller
public class PatientController {
ObjectMapper Obj = new ObjectMapper();
#GetMapping("/patient")
public static String patientForm(Model model) {
model.addAttribute("patient", new PatientDataModel());
model.addAttribute("patient1", new PatientDataModel1());
return "patient";
}
#RequestMapping(value="/patient", method=RequestMethod.POST, params="action=Send data to MongoDB cluster")
public static String patientSubmit(#ModelAttribute("patient") PatientDataModel patient, #ModelAttribute("patient1") PatientDataModel patient1, Model model, Object obj ) throws JsonProcessingException {
model.addAttribute("patient", patient);
model.addAttribute("patient1", patient1);
return "result";
}
and here are the views:
patient.html
<form action="#" th:action="#{/patient}" th:object="${patient}" method="post">
<div th:object="${patient1}" >
<p>Patient Id: <input type="text" th:value="${patient.id}" /></p>
<p>Patient Name: <input type="text" th:value="${patient.name}" /></p>
<p>Message: <input type="text" th:value="${patient.content}" /></p>
<p>address: <input type="text" th:value="${patient1.address}" /></p>
</div>
<p><input type="submit" name="action" value="Send data to MongoDB cluster" />
<input type="reset" value="Reset" /></p>
</form>
</div>
and result.html
<div class="starter-template">
<h1>Result</h1>
<p th:text="'id: ' + ${patient.id}" />
<p th:text="'Name: ' + ${patient.name}" />
<p th:text="'content: ' + ${patient.content}" />
<p th:text="'address: ' + ${patient1.address}" />
Submit another message
</div>
and the bean classes are : PatientDataModel.java
public class PatientDataModel {
private long id;
private String content;
private String name;
public PatientDataModel()
{
}
public PatientDataModel(long id, String content, String name)
{
this.id = id;
this.content = content;
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
#Override
public String toString()
{
return "Patient [id=" + id + ", firstName=" + name + ", " +
"content=" + content + "]";
}
}
another bean :
public class PatientDataModel1 {
private String address;
#Override
public String toString() {
return "Patient1 [address=" + address + "]";
}
public PatientDataModel1()
{
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
now , the issue is , I need both the beans to be accessible in the GET and POST method.
when I am running the code , it is executing but the beans does not have values , all are null . pls suggest
It will be easiest to have 1 object to find to the form. Create a new class PatientFormData for example that contains all the fields from the 2 objects and convert from/to the objects you have in the get and post methods in your controller.
For example:
public class PatientFormData {
private long id;
private String content;
private String name;
private String address;
public static PatientFormData from(PatientDataModel model,
PatientDataModel1 model1) {
id = model.getId();
content = model.getContent();
name = model.getName();
address = model.getAddress();
}
public PatientDataModel createPatientDataModel() {
PatientDataModel result = new PatientDataModel();
result.setId(id);
result.setContent(content);
result.setName(name);
return result;
}
// getters and setters here
}
Use this in the controller:
#Controller
public class PatientController {
ObjectMapper Obj = new ObjectMapper();
#GetMapping("/patient")
public static String patientForm(Model model) {
PatientFormData formData = PatientFormData.from(new PatientDataModel(), new PatientDataModel1());
model.addAttribute("patientFormData", formData);
return "patient";
}
#RequestMapping(value="/patient", method=RequestMethod.POST, params="action=Send data to MongoDB cluster")
public static String patientSubmit(#ModelAttribute("patientFormData") PatientFormData formData, Model model, Object obj ) throws JsonProcessingException {
PatientDataModel model = formData.createPatientDataModel();
PatientDataModel1 model1 = formData.createPatientDataModel1();
// Do more processing with objects
return "result";
}
Also be sure to correctly use the field binding using *{..}:
<form action="#" th:action="#{/patient}" th:object="${patientFormData}" method="post">
<p>Patient Id: <input type="text" th:value="*{id}" /></p>
<p>Patient Name: <input type="text" th:value="*{name}" /></p>
<p>Message: <input type="text" th:value="*{content}" /></p>
<p>address: <input type="text" th:value="*{address}" /></p>
</div>
<p><input type="submit" name="action" value="Send data to MongoDB cluster" />
<input type="reset" value="Reset" /></p>
</form>
</div>

Hibernate DAO cannot save foreign key using drop down list with spring boot and thymeleaf and i dont want to use jpa

this is my html code my code always save null in foreign key columns
please help and try to correct my code please
<div th:if="${mode == 'MODE_NEW'}">
<div class="container">
<div class="row">
<form autocomplete="off"
th:action="#{/admin/user-task/save}"
th:object="${user_task}" method="post" class="form-horizontal"
role="form">
<fieldset>
<!-- Form Name -->
<legend>User Task Assignment</legend>
<!-- Text input-->
<input type="hidden" name="id" th:field="${user_task.id}" />
<div class="form-group">
<label class="col-md-4 control-label">User</label>
<div class="col-md-4 text-left">
<select class="selectpicker" data-live-search="true"
title="Select User" name="user" tabindex="-98">
<option th:each="user: ${users}" th:value="${user.id}"
th:text="${user.name}"></option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Task</label>
<div class="col-md-4 text-left">
<select class="selectpicker" data-live-search="true"
title="Select Task" name="task" tabindex="-98">
<option th:each="task: ${tasks}" th:value="${task.id}"
th:text="${task.name}"></option>
</select>
</div>
</div>
<!-- Button (Double) -->
<div class="form-group">
<label class="col-md-4 control-label" for="submitButton"></label>
<div class="col-md-8">
<button type="submit" id="submitButton" name="submitButton"
class="btn btn-success">Save</button>
<button type="button" class="btn btn-inverse"
onclick="window.history.back()">Cancel</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
this is my controller where i have tried every thing but it not save directly please suggest in my code
#RequestMapping(value = "/save", method = RequestMethod.POST)
public ModelAndView saveUserTask(#Valid UserTask userTask,BindingResult bindingResult) throws UserTaskException {
ModelAndView modelAndView = new ModelAndView("redirect:/admin/user-task/all");
modelAndView.addObject("auth", getUser());
modelAndView.addObject("control", getUser().getRole().getRole());
User user=new User();
user.getUserTask();
Task task =new Task();
task.getUserTask();
userTask.setTask(task);
userTask.setUser(user);
userTaskService.save(userTask);
return modelAndView;
}
this is my dao interface in which calls method
public interface UserTaskDao {
public void save(UserTask user_task) throws UserTaskException;
}
this my DaoImpl in which I use hibernate session
#Override
public void save(UserTask user_task) throws UserTaskException {
Session session = this.sessionFactory.getCurrentSession();
try {
session.save(user_task);
}catch(HibernateException e) {
throw new UserTaskException("Error while saving user Task id and role id: "+e);
}
}
this is my service class
#Service
#Transactional
public class UserTaskService {
#Autowired
private final UserTaskDao userTaskDao; //userTaskDao
public UserTaskService(UserTaskDao userTaskDao) {
this.userTaskDao = userTaskDao;
}
public void save(UserTask user_task) throws UserTaskException{
userTaskDao.save(user_task);
}
}
My UserTask.java Class
#Entity(name="user_task")
public class UserTask implements Serializable {
#Id
#GeneratedValue
private int id;
#ManyToOne
#JoinColumn(name = "USER_ID", referencedColumnName = "id")
private User user;
#ManyToOne
#JoinColumn(name = "TASK_ID", referencedColumnName = "id")
private Task task;
public UserTask(UserTaskBean userTaskBean) {
}
public UserTask() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Task getTask() {
return task;
}
public void setTask(Task task) {
this.task = task;
}
}
In my User.java class
#OneToMany(mappedBy = "user")
private Set<UserTask> userTask = new HashSet<UserTask>();
In my Task.java class
#OneToMany(mappedBy = "task")
private Set<UserTask> userTask = new HashSet<UserTask>();

Cannot convert value of type 'java.lang.String' to required type 'java.time.LocalDate'

To run the application i use tomcat 8.5.50 package in war. i use spring 5.2 version.
in all operations I use JpaRepository. I do not use date time converters in my code - maybe this is a mistake?
I want to add a date to my table using jsp:
<div id="row">
<%--#elvariable id="mealsCreate" type=""--%>
<form:form action="${pageContext.request.contextPath}/create"
modelAttribute="mealsCreate" method="post">
<div class="col-md-9">
<input type="hidden"/>
<div class="form-group">
<div class="col-md-12">
<label for="dateTime">DateTime</label>
<input id="dateTime" type="date" name="datetime"/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="description" type="table" class="table">Description</label>
<input id="description" type="text" name="description"/>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<label for="calories" type="table" class="table">Calories</label>
<input id="calories" type="number" name="calories"/>
</div>
</div>
<button type="submit" class="btn btn-default" name="saveMeals">Save</button>
<button type="button" class="btn btn-default" name="cancelMeals" onclick="window.history.back()">Cancel</button>
</div>
</form:form>
</div>
but I get an error:
error in log:
Field error in object 'mealsCreate' on field 'datetime': rejected
value [2020-04-29]; codes
[typeMismatch.mealsCreate.datetime,typeMismatch.datetime,typeMismatch.java.time.LocalDate,typeMismatch];
arguments
[org.springframework.context.support.DefaultMessageSourceResolvable:
codes [mealsCreate.datetime,datetime]; arguments []; default message
[datetime]]; default message [Failed to convert property value of type
'java.lang.String' to required type 'java.time.LocalDate' for property
'datetime'; nested exception is java.lang.IllegalStateException:
Cannot convert value of type 'java.lang.String' to required type
'java.time.LocalDate' for property 'datetime': no matching editors or
conversion strategy found]] 22:16:59.659 [localhost-startStop-2] INFO
o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA
EntityManagerFactory for persistence unit 'default'
my model:
#Entity
#Table(name="meals")
public class Meal {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id")
private int id;
#Column(name = "date_time")
private LocalDate datetime;
#Column(name = "description")
private String description;
#Column(name = "calories")
private int calories;
public Meal() {
}
public Meal(int id) {
this.id = id;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public LocalDate getDatetime() {
return datetime;
}
public void setDatetime(LocalDate datetime) {
this.datetime = datetime;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getCalories() {
return calories;
}
public void setCalories(int calories) {
this.calories = calories;
}
}
nothing is loaded into the database either.
my sql inquiry:
CREATE TABLE meals
(
id integer NOT NULL,
date_time date,
description text NOT NULL,
calories integer NOT NULL,
CONSTRAINT meals_pkey PRIMARY KEY (id)
)
Controller:
#Controller
public class Controller {
#Autowired
MealService mealService;
#GetMapping(value = "/list")
public String getAll(Model model) {
model.addAttribute("meals", mealService.getAll());
return "meals";
}
#GetMapping(value = "/createForm")
public String addForm(Model model) {
Meal meal = new Meal();
model.addAttribute("mealsCreate", meal);
return "createmealForm";
}
#PostMapping(value = "/create")
public String save(#ModelAttribute("mealsCreate") Meal meal) {
mealService.save(meal);
return "redirect:/list";
}
}
what's wrong in my code?
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;
import java.beans.PropertyEditorSupport;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
/**
* #author yangxin
* #date 2020/10/27 15:32
* #since V1.0
*/
#ControllerAdvice
public class ControllerInitBinderHandler {
#InitBinder
protected void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(LocalDate.class, new PropertyEditorSupport() {
#Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(LocalDate.parse(text, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
});
binder.registerCustomEditor(LocalDateTime.class, new PropertyEditorSupport() {
#Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(LocalDateTime.parse(text, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
}
});
binder.registerCustomEditor(LocalTime.class, new PropertyEditorSupport() {
#Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(LocalTime.parse(text, DateTimeFormatter.ofPattern("HH:mm:ss")));
}
});
}
}

[Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.List' for property

I am working with Thymeleaf and trying to do some object binding, but I do not know how to do it if I have an object with a list. Let me explain:
My model:
#Entity
public class Project {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
private String name;
#NotNull
#Lob
private String description;
#NotNull
private Date startDate;
private String status;
#ManyToMany
private List<Role> rolesNeeded;
#ManyToMany
private List<Collaborator> collaborators;
public Project() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<Role> getRolesNeeded() {
return rolesNeeded;
}
public void setRolesNeeded(List<Role> rolesNeeded) {
this.rolesNeeded = rolesNeeded;
}
public List<Collaborator> getCollaborators() {
return collaborators;
}
public void setCollaborators(List<Collaborator> collaborators) {
this.collaborators = collaborators;
}
}
My html form:
<form method="post" action="addproject" th:object="${project}">
<div>
<label for="project_name"> Project Name:</label>
<input th:field="*{name}" type="text" name="project_name"/>
</div>
<div>
<label for="project_description">Project Description:</label>
<textarea th:field="*{description}" rows="4" name="project_description"></textarea>
</div>
<div>
<label for="project_status">Project Status:</label>
<div class="custom-select">
<span class="dropdown-arrow"></span>
<select th:field="*{status}" name="project_status">
<option value="active">Active</option>
<option value="archived">Archived</option>
<option value="not_started">Not Started</option>
</select>
</div>
</div>
<div>
<label for="project_roles">Project Roles:</label>
<ul class="checkbox-list">
<li th:each="role : ${roles}">
<input th:field="*{rolesNeeded}" type="checkbox" name="project_roles" th:value="${role}"/>
<span class="primary" th:text="${role.name}"> Developer</span>
</li>
</ul>
</div>
<div class="actions">
<input type="submit" value="Save" class="button"/>
Cancel
</div>
</form>
And I am getting the error:
ERROR!!!!: Field error in object 'project' on field 'rolesNeeded':
rejected value
[com.imprender.instateam.model.Role#145d6cd4,com.imprender.instateam.model.Role#73020d6f];
codes
[typeMismatch.project.rolesNeeded,typeMismatch.rolesNeeded,typeMismatch.java.util.List,typeMismatch];
arguments
[org.springframework.context.support.DefaultMessageSourceResolvable:
codes [project.rolesNeeded,rolesNeeded]; arguments []; default message
[rolesNeeded]]; default message [Failed to convert property value of
type 'java.lang.String[]' to required type 'java.util.List' for
property 'rolesNeeded'; nested exception is
java.lang.IllegalStateException: Cannot convert value of type
'java.lang.String' to required type
'com.imprender.instateam.model.Role' for property 'rolesNeeded[0]': no
matching editors or conversion strategy found]
Basically, as far as I understood, the checkbox input returns a String[], but my object needs a list, so the binding cannot be perfomed.
How could I bind the array in the list? (do you have an example?)
Thank you.
If Your Role bean has active boolean property, You could do something like this (simplified):
<ul class="checkbox-list">
<li th:each="role,stat : ${project.rolesNeeded}">
<input th:field="*{rolesNeeded[__${stat.index}__].active}" type="checkbox"/>
<input th:field="*{rolesNeeded[__${stat.index}__].name}" type="hidden"/>
<span class="primary" th:text="${role.name}">Developer</span>
</li>
</ul>
If it does not, you could store the rolesNeeded in the hidden fields and populate them with javascript.

Form validation error messages not appearing as expected

<td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" class="red">You must provide a reason for your request.</td>
<td th:if="${#fields.hasErrors('selectedDate')}" th:errors="*{selectedDate}" class="red">You must select a date.</td>
Why are these td being populated by the following messages instead of the messages I have provided above? They also don't take on the css class I provided.
may not be empty may not be empty
Request Entity:
public class RequestModel {
private Long requestId;
#NotNull
#NotBlank
private String selectedDate;
private RequestStatus requestStatus;
#NotNull
#NotBlank
private String description;
private Boolean hasForced;
public String getSelectedDate() {
return selectedDate;
}
public void setSelectedDate(String selectedDate) {
this.selectedDate = selectedDate;
}
public Long getRequestId() {
return requestId;
}
public void setRequestId(Long requestId) {
this.requestId = requestId;
}
public RequestStatus getRequestStatus() {
return requestStatus;
}
public void setRequestStatus(RequestStatus requestStatus) {
this.requestStatus = requestStatus;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getHasForced() {
return hasForced;
}
public void setHasForced(Boolean hasForced) {
this.hasForced = hasForced;
}
}
Controller:
#RequestMapping(value = "/save", method = RequestMethod.POST)
String saveRequest(Principal principal, #Valid #ModelAttribute(value = "requestModel") RequestModel requestModel, BindingResult bindingResult, RedirectAttributes redirectAttributes) {
if (bindingResult.hasErrors()) {
// log.info("There are binding errors.");
return "send";
}
...
}
The full HTML form:
<form role="form" th:action="#{/request/save}" th:object="${requestModel}" method="post">
<input type="checkbox" th:field="*{hasForced}" th:checked="${false}" style="display: none;"/>
<p><input id="description" class="descriptionField" type="text" th:field="*{description}"
placeholder="Please provide a reason for your request"
style="width: 500px; border-radius: 4px; padding: 11px 11px 11px 11px;"/></p>
<input id="embeddedDateField" class="dateField" placeholder="YYYY-MM-DD" type="text" th:field="*{selectedDate}" readonly
style="border-radius: 4px; background: #eefdff; text-align: center;"/><br>
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
<div style="margin: 5px; width: 200px;"><input type="submit" value="Submit Request"
style="display: block;"></div>
<td th:if="${#fields.hasErrors('description')}" th:errors="*{description}" class="red">You must provide a reason for your request.</td>
<td th:if="${#fields.hasErrors('selectedDate')}" th:errors="*{selectedDate}" class="ed">You must select a date.</td>
</form>
What's going on here?
These messages are coming from validation annotation default values. To set your own you need to provide them like below or you can change from properties file using MessageSource.
#NotNull(message="You must select a date.")
#NotBlank(message="You must select a date.")
private String selectedDate;

Categories

Resources