Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a jsp tag to hide an input field on load

Tags:

jsp

jstl

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?

like image 886
coder Avatar asked Nov 27 '22 18:11

coder


2 Answers

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'}">
like image 109
BalusC Avatar answered Dec 04 '22 07:12

BalusC


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>
like image 45
ace Avatar answered Dec 04 '22 06:12

ace