Form validation error messages not appearing as expected - java

<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;

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>

Cannot print in HTML ArrayList using Spring MVC

I am facing problem trying print at the same time a form and array in the same HTML.
Here is my usuario class:
public class usuario {
private String user_id;
private String createdAt;
private String address;
private String latitude;
private String longitude;
private String birthday;
private String email;
private String user_idp;
private ArrayList pedido;
private String phoneNunmber;
private Integer edad;
public String nombre;
private String confirmationCode;
private String promotions;
public String ciudad;
public String getCiudad() {
return ciudad;
}
public void setCiudad(String ciudad) {
this.ciudad = ciudad;
}
public String getPromotions() {
return promotions;
}
public void setPromotions(String promotions) {
this.promotions = promotions;
}
public String getConfirmationCode() {
return confirmationCode;
}
public void setConfirmationCode(String confirmationCode) {
this.confirmationCode = confirmationCode;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public Integer getEdad() {
return edad;
}
public void setEdad(Integer edad) {
this.edad = edad;
}
public String getPhoneNunmber() {
return phoneNunmber;
}
public void setPhoneNunmber(String phoneNunmber) {
this.phoneNunmber = phoneNunmber;
}
public String getUser_idp() {
return user_idp;
}
public void setUser_idp(String user_idp) {
this.user_idp = user_idp;
}
public ArrayList getPedido() {
return pedido;
}
public void setPedido(ArrayList pedido) {
this.pedido = pedido;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getUser_id() {
return user_id;
}
public void setUser_id(String user_id) {
this.user_id = user_id;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
}
Here is my Controller code:
#Controller
public class GreetingController {
#GetMapping("/allusers")
public String greetingForm(Model model) throws ParseException{
tablausuario tu = new tablausuario();
ArrayList<usuario> user = tu.listausuarios();
Collections.sort(user, (o1, o2) -> o2.getCreatedAt().compareTo(o1.getCreatedAt())); //tabla ordenada
model.addAttribute("TodosLosUsuarios", user);
return "greeting";
}
#PostMapping("/allusers")
public String greetingSubmit(Model model, HttpServletRequest request, #ModelAttribute usuario users) {
String ciudad = request.getParameter("ciudad");
tablausuariofilterbycity tufc = new tablausuariofilterbycity();
ArrayList<usuario> userbycity = tufc.listausuariosfiltradosporciudad(ciudad);
model.addAttribute("TodosLosUsuarios", userbycity);
return "result";
}
}
And here is my HTML "greeting"
<div class="container">
<h2>Listado de usuarios </h2>
<p th:text=" ${TodosLosUsuarios.size()} "></p>
<div id="capa"> </div>
<h1>Form</h1>
<form action="#" th:action="#{/allusers}" th:object="${TodosLosUsuarios}" method="post">
<p>Message: <input type="text" th:field="*{ciudad}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
<input type="text" id="myInput" onkeyup="myFunction()" placeholder="Buscar por ciudad..">
<table id="myTable" class="table table-bordered">
<thead>
<tr>
<th>Nombre</th>
<th>Email</th>
<th>Teléfono</th>
<th>Día creado</th>
<th>Edad</th>
<th>Confirmado</th>
<th>Promocion</th>
<th>Direccion</th>
</tr>
</thead>
<tbody th:each="usuariosTotales: ${TodosLosUsuarios}" >
<tr>
<td th:text=" ${usuariosTotales.getNombre()} " ></td>
<td th:text=" ${usuariosTotales.getEmail()} " ></td>
<td th:text=" ${usuariosTotales.getPhoneNunmber()} " ></td>
<td th:text=" ${usuariosTotales.getCreatedAt()} " ></td>
<td th:text=" ${usuariosTotales.getEdad()} " ></td>
<td th:text=" ${usuariosTotales.getConfirmationCode()} " ></td>
<td th:text=" ${usuariosTotales.getPromotions()} " ></td>
<td th:text=" ${usuariosTotales.getAddress()} " ></td>
</tr>
</tbody>
</table>
</div>
</div>
I am sure that the problem is in the form:
<form action="#" th:action="#{/allusers}" th:object="${TodosLosUsuarios}" method="post">
<p>Message: <input type="text" th:field="*{ciudad}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
If instead of "user" I use "new usuario"
model.addAttribute("TodosLosUsuarios", user);
I use
model.addAttribute("TodosLosUsuarios", new usuario());
the form works but I am not able to read the ArrayList, and I get this error:
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "greeting" - line 10, col 40)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
... 48 more
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "greeting" - line 10, col 40)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117)
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95)
at org.thymeleaf.util.ProcessorConfigurationUtils$ElementTagProcessorWrapper.process(ProcessorConfigurationUtils.java:633)
at org.thymeleaf.engine.ProcessorTemplateHandler.handleStandaloneElement(ProcessorTemplateHandler.java:918)
at org.thymeleaf.engine.TemplateHandlerAdapterMarkupHandler.handleStandaloneElementEnd(TemplateHandlerAdapterMarkupHandler.java:260)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler$InlineMarkupAdapterPreProcessorHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:256)
at org.thymeleaf.standard.inline.OutputExpressionInlinePreProcessorHandler.handleStandaloneElementEnd(OutputExpressionInlinePreProcessorHandler.java:169)
at org.thymeleaf.templateparser.markup.InlinedOutputExpressionMarkupHandler.handleStandaloneElementEnd(InlinedOutputExpressionMarkupHandler.java:104)
at org.attoparser.HtmlElement.handleStandaloneElementEnd(HtmlElement.java:79)
at org.attoparser.HtmlMarkupHandler.handleStandaloneElementEnd(HtmlMarkupHandler.java:241)
at org.attoparser.MarkupEventProcessorHandler.handleStandaloneElementEnd(MarkupEventProcessorHandler.java:327)
at org.attoparser.ParsingElementMarkupUtil.parseStandaloneElement(ParsingElementMarkupUtil.java:96)
at org.attoparser.MarkupParser.parseBuffer(MarkupParser.java:706)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:301)
... 50 more
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'ciudad' of bean class [java.util.ArrayList]: Bean property 'ciudad' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:622)
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:612)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:158)
at org.springframework.web.servlet.support.RequestContext.getBindStatus(RequestContext.java:903)
at org.thymeleaf.spring5.context.webmvc.SpringWebMvcThymeleafRequestContext.getBindStatus(SpringWebMvcThymeleafRequestContext.java:227)
at org.thymeleaf.spring5.util.FieldUtils.getBindStatusFromParsedExpression(FieldUtils.java:306)
at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:253)
at org.thymeleaf.spring5.util.FieldUtils.getBindStatus(FieldUtils.java:227)
at org.thymeleaf.spring5.processor.AbstractSpringFieldTagProcessor.doProcess(AbstractSpringFieldTagProcessor.java:174)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:74)
... 63 more
I think the problem is your are using plain HTML (ie tag form) instead of the Spring JSP Form
<form:form method="POST" action="/todoslosusuarios"
modelAttribute="TodosLosUsuarios">
I think you are missing the proper tags for action in Thymeleaf and also the "post" method declaration.
<form action="#" th:action="#{/todoslosusuarios}" method="post">
this link covers the process end to end.
https://spring.io/guides/gs/handling-form-submission/

[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 gives Nulls when submitted

I am using Spring MVC + thymeleaf and when I am submitting my form it gives me all the time validation error(Null) in the binding result. Any advise would be appreciated! Thanks!
Error message
"Field error in object 'createForm' on field 'authorId': rejected value [null]; codes [NotNull.createForm.authorId,NotNull.authorId,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [createForm.authorId,authorId]; arguments []; default message [authorId]]; default message [may not be null]"
#NotNull
#Size(min= 2, max = 100, message = "your title should be between 2 and 100 symbols")
private String title;
#NotNull
#Size(min = 2, message = "Please fill your message")
private String content;
#DateTimeFormat(pattern = "yyyy-mm-dd")
private Date date;
#NotNull
private String authorId;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getId() {
return authorId;
}
public void setId(String authorId) {
this.authorId = authorId;
}
}
And my HTML
<form id="create-form" method="post" th:object="${createForm}">
<div><label for="title">Title:</label></div>
<input id="title" type="text" name="title" th:value="*{title}"/>
<span class="formError" th:if="${#fields.hasErrors('title')}" th:errors="*{title}">Invalid title</span>
<div><label for="content">Content:</label></div>
<textarea name="content" rows="30" cols="100" id="content" th:value="*{content}"></textarea>
<span class="formError" th:if="${#fields.hasErrors('content')}" th:errors="*{content}">Invalid content</span>
<div><label for="date">Date:</label></div>
<input id="date" type="date" name="date" th:value="*{date}"/>
<span class="formError" th:if="${#fields.hasErrors('date')}" th:errors="*{date}">Invalid date</span>
<div><label for="authorId">Author ID:</label></div>
<input id="authorId" type="text" name="authorId" th:value="*{authorId}"/>
<span class="formError" th:if="${#fields.hasErrors('id')}" th:errors="*{authorId}">Invalid id</span>
<br/>
<br/>
<div><input type="submit" value="Create"/></div>
</form>
As written in the comment to the question:
Annotation #NotNull won't protect you from null. It's your own contract with you and other developers working on this code that there can't be null there.
This means that you have to validate data by yourself. There are two approaches. You can create AuthorTO which will allow nulls and then create Author if and only if there are no unexpected nulls or validate on front-end side.

JSP Method not found: class java.lang.String

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}">

Categories

Resources