[ACCEPTED]-Can I use a jsp tag to hide an input field on load-jstl

Accepted answer
Score: 16

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'}">
Score: 10

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:when test="${inputDisplay == 1}">
        <input type="text" />
        <input type="text" style="display:none;" />
Score: 4

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

More Related questions