Display element in JSP only if model element not null


Dev-Bookmarks Logo

(P) Bookmarks.dev - Open source Bookmarks and Code Snippets Manager for Developers & Co. See our How To guides to help you get started. Public Bookmarks Repo on Github - Star


How to display element in JSP only if model element not null

To do that you can use the or _ tags to make conditional rendering in Java Server Pages (JSP) using the JSP Standard Tag Library (JSTL) like in the following code snippet:

<div>
	<c:if test="${not empty podcast.twitterPage}">
		<a href="${podcast.twitterPage}" target="_blank" class="icon-twitter-producer producer-social"></a>
	</c:if> 			 		
	<c:if test="${not empty podcast.fbPage}">
		<a href="${podcast.fbPage}" target="_blank" class="icon-facebook-producer producer-social"></a>
	</c:if> 			 		
	<c:if test="${not empty podcast.gplusPage}">
		<a href="${podcast.gplusPage}" target="_blank" class="icon-google-plus-producer producer-social"></a>
	</c:if> 
</div>

Podcastpedia.org on GitHub

Subscribe to our newsletter for more code resources and news

How to filter results list in Angular with input text

Real life example showing how to filter results list in Angular and its implementation with Angular pipes. Continue reading

GraphQL Resources to help you get started

Published on November 05, 2020