How would you port this front-end logic from erb to jsp/jstl?
<%= error_messages_for :foo %>
Is there any Java library that does something similar?
How would you port this front-end logic from erb to jsp/jstl?
<%= error_messages_for :foo %>
Is there any Java library that does something similar?
Maintain them in a Map<String, String>
in the business code, put it in the request scope like so:
Map<String, String> messages = new HashMap<String, String>();
request.setAttribute("messages", messages);
// ...
messages.put("foo", "Please enter valid value");
Then you can access it in JSP the usual EL way by ${messages.key}
or ${messages['key']}
:
<input id="foo" name="foo" value="${fn:escapeXml(param.foo)}">
<label for="foo" class="error">${messages.foo}</label>
EL is builtin in JSP since ages. You don't need to install it. Only the fn:escapeXml
(which is mandatory to prevent XSS) is part of JSTL which may need to be installed separately at certain servletcontainers.