Use El to judge enumeration value equality problem in JSP __js

Source: Internet
Author: User

Passing variables to the view in SPRINGMVC are enumerated types, defined as:
Package Com.xxx.pojo;

public enum Createuserresult {
	success,duplicateloginname
}

The value passed to the view is named result
This will fail when determining whether result is createuserresult.duplicateloginname in the JSP, as follows:
<c:choose>
	<c:when test= "${result eq createuserresult.duplicateloginname}" >
	<span class= " Error > The sign-in name you entered already exists, please replace the sign-in name and try again. </span></c:when>
<c:otherwise></c:otherwise>
</c:choose>

The reason for the failure is that the EL Lookup variable is looking for a variable from a range of page,request,session, Createuserresult.duplicateloginname is an enumerated type value, and there is no way to write it directly.
One trick to do this is to set a variable with a jstl set expression and compare it. The following code
<c:set var= "Duplicateloginname" value= "<%=createuserresult.duplicateloginname%>"/> <c:if test= "${not Empty Result}" > <c:choose> <c:when test= "${result eq duplicateloginname}" > <spa N class= "Error" > The sign-in name you entered already exists, please replace the sign-in name and try again. </span></c:when> <c:otherwise></c:otherwise> </c:choose> </c:if> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.