maven - Showing (or not) a DIV or other HTML tag with JSTL if a variable exist -


i'm teaching myself how work jstl.

i'm having problems showing/not showing div on view when variable set o not controller.

i'm working on spring boot maven project tiles template management.

i set variable fine in controller , can see in jsp view, , in case show in div, follows:

<c:if test="${!empty loggeduser}">     <div class="alert alert-success alert-dismissible" role="alert">         <button type="button" class="close" data-dismiss="alert"             aria-label="close">             <span aria-hidden="true">&times;</span>         </button>         <strong>${loggeduser.email}</strong> welcome new project!     </div> </c:if> 

i expect code if loggeduser variable set, print whole div tag "email welcome" alert, next image: jstl working fine

by other hand, if loggeduser variable not set, or not exist, div not showed @ all. got when loggeduser doesn't exist div showing without user email in alert. next image: jstl not working expected

what need if set variable in controller, show complete div. if variable not set or doesn't exist, don't show/print div.

p.s: controller's method.

@postmapping("/login/entry") public string checkuserinfo(@valid loginuser loginuser, bindingresult bind, model model) {     logger.info("entry");     if (bind.haserrors()) {         logger.info("bind has errors");         model.addattribute("hidetemplates", true);         return "loginpage";     }     model.addattribute("loggeduser", loginuser);     return "aboutpage"; } 

i'm working tiles templates management. problem here jsp line <%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core' %> not included in cascade.

i solved problem including jsp line on every view file had use jstl el.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -