I was wondering if there is a way to register default renderer for a particular class in JSP/JSTL.
I am on my page displaying a tabular report where each table row arrives as generic List<Object>. Since I don’t know the type of particular item in advance I am outputting the value with <c:out ...>. This does toString() as far as I know.
Now I want to change the format based on the class of the item e.g. change the format of decimal numbers. Of course I can’t use <fmt:formatXXX ...> because I don’t know the type in advance.
I believe this is possible in JSF. But is there a way how to achieve this in JSP?
My best shot sofar would be to convert the List<Object> to List<String> and applying the formatting in my controller class but this is slightly less elegant than register a renederer IMHO.
JSP has no notion of “renderers”, it’s not a component based MVC framework. But you could create a custom tag for this.
Alternatively, you can do something like this with plain JSTL, it’s possible to figure the class of an EL object by just checking
Object#getClass():