Reputation: 3510
I have a jsp page with a List<Object>
as the @ModelAttribute
. However, there are no <form:form>
tags in the page. All I'm doing is print the contents of the List
.
In my Controller.java
, I'm binding an error by doing:
result.rejectValue("", "NOT_LOGGED_IN", "You should Login first") ;
But since I dont have a form in my jsp, I'm not able to access the error with:
<form:errors path="" /> <br/>
Please tell me how to access the error (or what I'm doing wrong).
Upvotes: 4
Views: 9445
Reputation: 401
Check if Expression Language evaluation is enabled in JSP(By default it is disabled).If not add below code to enable it.
<%@ page isELIgnored="false" %>
Upvotes: 0
Reputation: 21
there's a way to reference the error like
instead of
<form:form commandName="object">
<form:errors path="field"/>
</form:form>
best
Upvotes: 0
Reputation: 36
for any specific error set in your code like-
model.addObject("errorMsg","username/password failed");
And show this error on jsp in this way:
<c:out value="${errorMsg}"/>
This way you would get your error on jsp.
Upvotes: 0
Reputation: 48817
In your controller:
model.addAttribute("errors", result.getAllErrors());
In your JSP:
<c:forEach items="${errors}" var="error">
<%-- do want you want with ${error} --%>
<c:out value="${error.defaultMessage}" />
</c:forEach>
Upvotes: 6
Reputation: 49915
Associate global errors this way:
result.reject("NOT_LOGGED_IN", "You should Login first") ;
You can show the global errors in the jsp :
<form:errors cssClass="error" delimiter="<p/>" />
Upvotes: 3