0

I have the following piece of code that evaluates to true:

<c:choose>
    <c:when test="${not isAddressNotFound}">
            <%-- Always evaluates to true -->
    </c:when>
</c:choose>

However, the isAddressNotFound variable is never defined in the code.

Is this a feature at the time of evaluating a variable that has been never defined instead of throwing an error? If so, what would be the benefits of doing so?

Eder
  • 1,806
  • 16
  • 33
  • 3
    EL is smart enough to avoid such `NullPointerException`. Try `Value:"${isAddressNotFound}"` that prints `Value:""` it means if variable is found/declared then it convert it to empty string. If you are looking for solution then try with `${not empty isAddressNotFound}` that checks for `null` as well as emptyness. – Braj Jul 03 '14 at 18:44
  • 3
    Try `${isAddressNotFound != null}` check. Read more [Evaluate empty or null JSTL c tags](http://stackoverflow.com/questions/2811626/evaluate-empty-or-null-jstl-c-tags) – Braj Jul 03 '14 at 18:50

1 Answers1

0

I think a better approach for testing whether or not one variable is defined is the tag

<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>

That you can use with

<logic:present name="isAddressNotFound">
    User object exists.
</logic:present>

or

<logic:notPresent name="isAddressNotFound">
    User object does not exists.
</logic:notPresent>

In order to fully accomplish your goals.

Rafael dAS
  • 109
  • 4