I need to hide a field on page load based on the value of a request attribute. I don't want a 'hidden' field because I want to show it again. I don't want to do this with javascript. How is this done with jsp tags?
Use the conditional operator in EL.
<div class="${hide ? 'hide' : 'show'}">
where ${hide}
is the request attribute evaluating to a boolean
. If it evaluates true
, then the class name "hide"
will be printed, else the class name "show"
will be printed.
Of course define those classes in your stylesheet as well.
.hide { display: none; }
.show { display: block; }
No need for JSTL tags here.
Or if you don't want to use CSS class definitions for some unobvious reason, then do
<div style="display:${hide ? 'none' : 'block'}">
Set a condition where display is block if the condition is true. Else if the condition 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With