Alex Rivera | Logout

Check if variable exists in JSTL

Asked 2011-08-11T09:05:56.743
9

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

Edit
Report

1 Answer

10

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>
answered 2011-08-11T09:11:41.840

Your Answer