Best practice for Java references inside my JSPs

I ask for some opinions regarding the reference to Java code (in my case the value of the enumeration) in the JSP.

I currently have conditional logic in my JSP:

<c:if test="${actionBean.order.status eq 'complete'}">    
    show some stuff
</c:if>

Now "complete" is the value associated with the enumeration in my code base. Would it be better to reference the enum inside my JSP? If so, how?

I think this may be good, because: if the enumeration changes, the JSP is not interrupted.

Is it wrong to use Java code in JSP? Or worse, to duplicate the value of "complete"?

Thanks in advance.

+5
source share
3 answers

Is it wrong to use Java code in JSP? Or worse, to duplicate the value of "complete"?

, Java- JSP, /.

: , Java, "" JSP. , , "actionBean", getOrder() getStatus() . getOrder() null - . , Java, taglibs.

+1

, JSP, , String.valueOf(enum), . , , JSP. . String String.valueOf(enum), String . .

Java- JSP :

Java, (in), HttpServlet, :

+1

Can't you make the logic for whether you want to “show some things” outside the JSP and just pass a simple boolean parameter to indicate whether to display or not? This way you avoid duplicating the enumeration value, and you also store this bit of logic in the controller, and not in the view.

0
source

All Articles