Can jstl check if attribute has been added to the model?
Is it possible to check if an attribute has been added to the model?
//in the controller teh variable is not always added
//
model.addAttribute("variable", myVariable);
and in the jsp something like this
<c:choose>
<c:when test="${variable is present}">
Not present
</c:when>
<c:otherwis开发者_运维百科e>
Present
</c:otherwise>
</c:choose>
Thanks
JSTL/EL cannot check if an attribute has been added to the model. For that you need to implement an observer/observable yourself.
EL can however check if a bean property or a map value is not null or empty.
<c:when test="${not empty bean.property}">
<c:when test="${not empty map.key}">
See also:
- Java EE tutorial - Overview of EL operators
- Java EE tutorial - Examples of EL expressions
You can check if the attribute is empty
<c:if test="${not empty post}">
<h3>${post.title}</h3>
</c:if>
精彩评论