Thymeleaf select and CriteriaBuilder
<p>It's a simple thing I want to do that somehow raises a complex issue.. I'm going insane over this...</p>

<p>I want to compare my Pages field using criteriabuilder; get all that are less than, so use 'le' for numbers ('lessThanOrEqualTo' doesn't work here ). </p>

<p>How can you send an Integer from a Thymeleaf select so that if it is not selected it won't be added to your search criteriaBuilder ?</p>

<p>In the select you're forced by thymeleaf to have a String "undefined" option as a first option. If I use Integer as the field type it won't bind this "undefined" option to the posted model where I would later filter it out from the criteriabuilder. The numbers are OK here though. I need it to work if not selected or undefined.</p>

<p>If I go the other way and choose a String field for Pages then it will not be parsed for ...
      le(Expression x, Expression y) </p>

<p>in the CriteriaBuilder. I cannot turn </p>

<pre><code> b.get("pages") 
</code></pre>

<p>into </p>

<pre><code>Expression&lt;? extends Number&gt; myInteger
</code></pre>

<p>I've tried everyway....</p>

<pre><code>                        &lt;select th:field="*{pages}"  ng-model="bookData.pages"&gt;
                        &lt;option selected="selected" value=""&gt;  select an option  &lt;/option&gt;
                        &lt;option th:each="selectItem: ${refData.pages}"

                              th:value="${selectItem.value}" 
                              th:text="${selectItem.label}"&gt;Pages&lt;/option&gt;
                        &lt;/select&gt;


    List&lt;Predicate&gt; predList = new LinkedList&lt;Predicate&gt;();

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery&lt;Book&gt; c =cb.createQuery(Book.class);
    Root&lt;Book&gt; b = c.from(Book.class);



    if( (!pages.equals("")) &amp;&amp; (!pages.equals("undefined")) ){
      predList.add(cb.lessThanOrEqualTo(b.get("pages"), pages));

    }
</code></pre>

<p>How could you send an Integer from a Thymeleaf select to be compared in the query so that if not selected doesn't get added to the query?</p>

<p>Ahhhhhhh!</p>