Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display error in JSP without a <form:form>

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).

like image 778
th3an0maly Avatar asked Jan 15 '23 12:01

th3an0maly


2 Answers

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>
like image 74
sp00m Avatar answered Jan 21 '23 03:01

sp00m


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="&lt;p/&gt;" />
like image 31
Biju Kunjummen Avatar answered Jan 21 '23 03:01

Biju Kunjummen