[ACCEPTED]-Can I use a jsp tag to hide an input field on load-jstl
Use the conditional operator in EL.
<div class="${hide ? 'hide' : 'show'}">
where 8 ${hide}
is the request attribute evaluating to 7 a boolean
. If it evaluates true
, then the class name 6 "hide"
will be printed, else the class name "show"
will 5 be printed.
Of course define those classes 4 in your stylesheet as well.
.hide { display: none; }
.show { display: block; }
No need for JSTL 3 tags here.
Or if you don't want to use CSS 2 class definitions for some unobvious reason, then 1 do
<div style="display:${hide ? 'none' : 'block'}">
Set a condition where display is block if 2 the condition is true. Else if the condition 1 is false set the display to none.
<c:set var="inputDisplay" value="1" /> <!-- This same as your request attribute -->
<c:choose>
<c:when test="${inputDisplay == 1}">
<input type="text" />
</c:when>
<c:otherwise>
<input type="text" style="display:none;" />
</c:otherwise>
</c:choose>
The following code will only show include 2 the code between the tags if requestAttribute
evaluates 1 to true
to have the opposite effect use ${not requestAttribute}
instead.
<c:if test="${requestAttribute}">
//Code here
</c:if>
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.