title: Comparing numeric values in JSTL/EL
body: <p>I'm comparing numeric values in the following way in JSTL.</p>
  
  <pre><code>&lt;c:set var="testValue" value="10"/&gt;
  
  &lt;c:choose&gt;
      &lt;c:when test="${testValue==10}"&gt;
          &lt;c:out value="Test is successful."/&gt;
      &lt;/c:when&gt;
      &lt;c:otherwise&gt;
          &lt;c:out value="Test is unsuccessful."/&gt;
      &lt;/c:otherwise&gt;
  &lt;/c:choose&gt;
  </code></pre>
  
  <p>The condition is evaluated to true and it displays - "Test is successful."</p>
  
  <p>If the value of the variable <code>testValue</code> is not numeric like,</p>
  
  <pre><code>&lt;c:set var="testValue" value="xxx"/&gt;
  </code></pre>
  
  <p>then the test fails with the following exception.</p>
  
  <blockquote>
    <p>javax.el.ELException: Cannot convert xxx of type class
    java.lang.String to class java.lang.Long</p>
  </blockquote>
  
  <p>Because the string is not parsable to <code>Long</code>. The comparison is done lexicographically.</p>
  
  <p>This can be avoided by using EL like the following.</p>
  
  <pre><code>&lt;c:set var="testValue" value="${xxx}"/&gt;
  </code></pre>
  
  <p>In this case, the text in the <code>&lt;c:otherwise&gt;</code> section would be displayed.</p>
  
  <hr>
  
  <p>I'm using such a construct while retrieving data from a database like,</p>
  
  <pre><code>&lt;c:forEach var="row" items="${list}" varStatus="loop"&gt;
      &lt;c:choose&gt;
          &lt;c:when test="${param.edId==row.id || row.id==param.id}"&gt;
              // Do something.
          &lt;/c:when&gt;
  
          &lt;c:otherwise&gt;
              // Do something.
          &lt;/c:otherwise&gt;
      &lt;/c:choose&gt;
  &lt;/c:foreach&gt;
  </code></pre>
  
  <p>In the above code, the value of <code>row.id</code> is guaranteed to be <code>Long</code> that corresponds to the <code>Number</code> datatype in the Oracle database.</p>
  
  <p>The values of <code>param.edId</code> and/or <code>param.id</code> are however not guaranteed to be numeric and can be changed by malicious users. In that case, an unexpected error as above may occur.</p>
  
  <hr>
  
  <p>Do I really need to set two extra variables for this like,</p>
  
  <pre><code>&lt;c:set var="paramId" value="${param.id}"/&gt;
  &lt;c:set var="paramEdId" value="${param.edId}"/&gt;
  </code></pre>
  
  <p>and use them in the loop above or is there a concise way to avoid that parse exception (in case, the values are not parsable)?</p>