I've got a PersistenceSet and would like to check if it contains a certain variable.
How can I check in the JSTL whether subitem exists or not?
However when I try to access a non-existant variable like this:
<c:if test="${not empty item.subitem}">
<c:out value="${item.subitem}" /><br />
</c:if>
I get a PropertyNotFoundException:
Property 'subitem' not found on type com.company.classname
JSTL <c:if> Core Tag It is more or like a if statement in java which evaluates a condition and executes a block of code if the result is true. Syntax: This is the basic syntax of <c:if> core tag. The set of statements enclosed within <c:if> tag gets executed if test=”true”.
C if Statement The if statement evaluates the test expression inside the parenthesis () . If the test expression is evaluated to true, statements inside the body of if are executed. If the test expression is evaluated to false, statements inside the body of if are not executed.
JSTL stands for JSP Standard Tag Library. JSTL is the standard tag library that provides tags to control the JSP page behavior. JSTL tags can be used for iteration and control statements, internationalization, SQL etc.
The Jakarta Standard Tag Library (JSTL; formerly JavaServer Pages Standard Tag Library) is a component of the Java EE Web application development platform.
It is clear that standard setter/getter is not available for subitem
in the class
If you want to check if the property is available for the class you can go for following tweak
using c:catch
<c:catch var="exception">${item.subitem}</c:catch>
<c:if test="${exception==null}">subitemnot available.</c:if>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With