I’m asking for some opinions on referencing Java code (in my case an enum value) in a JSP.
I currently have conditional logic in my JSP like:
<c:if test="${actionBean.order.status eq 'complete'}">
show some stuff
</c:if>
Now, ‘complete’ is a value associated with an enum in my codebase. Would it be better to reference the enum inside my JSP? If so, how?
I think it might be a good thing because: If the enum changes, then the JSP doesn’t break.
Is it bad practice to mix Java code into the JSPs? Or is it worse to duplicate the value of ‘complete’?
Thanks in advance.
My opinion is that you should avoid mixing Java code with JSPs, even if it means some limited duplication of symbols / values.
Think of it this way: there are many, many changes that could be made on the Java side that could “break” a JSP. In this case, for instance, the name of “actionBean”, the
getOrder()orgetStatus()methods could change. OrgetOrder()could return anullor something of a different type. If you worried about all of the things that could change on the Java side, you’d end up not using taglibs at all.