How to do if-else in Thymeleaf?

Thymeleaf has an equivalent to <c:choose> and <c:when>: the th:switch and th:case attributes introduced in Thymeleaf 2.0. They work as you’d expect, using * for the default case: <div th:switch=”${user.role}”> <p th:case=”‘admin'”>User is an administrator</p> <p th:case=”#{roles.manager}”>User is a manager</p> <p th:case=”*”>User is some other thing</p> </div> See this for a quick explanation of syntax … Read more

How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resolved

org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application That URI is for JSTL 1.0, but you’re actually using JSTL 1.2 which uses URIs with an additional /jsp path (because JSTL, who invented EL expressions, was since version 1.1 integrated as part of JSP 2.0 … Read more

JSTL in JSF2 Facelets… makes sense?

Introduction JSTL <c:xxx> tags are all taghandlers and they are executed during view build time, while JSF <h:xxx> tags are all UI components and they are executed during view render time. Note that from JSF’s own <f:xxx> and <ui:xxx> tags only those which do not extend from UIComponent are also taghandlers, e.g. <f:validator>, <ui:include>, <ui:define>, … Read more

Check a collection size with JSTL

<c:if test=”${companies.size() > 0}”> </c:if> This syntax works only in EL 2.2 or newer (Servlet 3.0 / JSP 2.2 or newer). If you’re facing a XML parsing error because you’re using JSPX or Facelets instead of JSP, then use gt instead of >. <c:if test=”${companies.size() gt 0}”> </c:if> If you’re actually facing an EL parsing … Read more

if…else within JSP or JSTL

Should I use JSTL ? Yes. You can use <c:if> and <c:choose> tags to make conditional rendering in jsp using JSTL. To simulate if , you can use: <c:if test=”condition”></c:if> To simulate if…else, you can use: <c:choose> <c:when test=”${param.enter==’1′}”> pizza. <br /> </c:when> <c:otherwise> pizzas. <br /> </c:otherwise> </c:choose>

Evaluate empty or null JSTL c tags

How can I validate if a String is null or empty using the c tags of JSTL? You can use the empty keyword in a <c:if> for this: <c:if test=”${empty var1}”> var1 is empty or null. </c:if> <c:if test=”${not empty var1}”> var1 is NOT empty or null. </c:if> Or the <c:choose>: <c:choose> <c:when test=”${empty var1}”> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)