I'm writing a JSP that sometimes needs to format a Java Date that comes out of the request. I'm doing it like this:
<fmt:formatDate value="${attribute.value}" pattern="yyyy-MM-dd HH:mm:ss"/>
and it works beautifully on Java Dates.
However, there are times that the request attribute field with the exact same name (attribute.value
) is not actually a date and should not be formatted as such. What I would like to do is simply pass that string through the fmt:format
tag as-is, rather than throwing an exception on an unparseable date.
I could accomplish something similar using a c:choose
but I'd rather separate the JSP view from the underlying data as much as possible, so this isn't the ideal choice for me. So, is there a way to make something like
<fmt:formatDate value="I AM NOT A DATE" pattern="yyyy-MM-dd HH:mm:ss"/>
evaluate to, simply,
I AM NOT A DATE
in the generated HTML?