How can I present a boolean value as yes or no?

How to replace true and false yes or no with JSP and JSTL?

I have TRUE and FALSE values ​​in my table.

I want to get these values ​​using jstl in my jsp pages, true false will replace YES and NO

+4
source share
2 answers

I would suggest using a tag file.

Create a tag file (e.g. /WEB-INF/tags/yesno.tag ) like this:

 <%@ attribute name="value" type="java.lang.Boolean" required="true" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <c:choose><c:when test="${value}">yes</c:when><c:otherwise>no</c:otherwise></c:choose> 

Then in your JSP:

 <%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%> <tags:yesno value="${MyBoolean}"/> 

The file tag is a bit bulky, but it is well encapsulated and reused.

+7
source

Another option is to use the JSP Expression Language and use the following in the JSP:

 ${myBoolean ? 'Yes' : 'No'} 
+4
source

Source: https://habr.com/ru/post/1312093/


All Articles