spring mvc - How to compare two variables of the model with Thymeleaf Standard Expression Syntax? -



spring mvc - How to compare two variables of the model with Thymeleaf Standard Expression Syntax? -

i'm trying set selected option's attribute thymeleaf + springmvc shown below:

(item.coditem , defaultcoditem long)

<select id="selitems"> <th:block th:each="item : ${myitems}"> <option value="564" th:value="${item.coditem}" th:selected="(${item.coditem} eq ${defaultcoditem})? 'selected' : '' " th:text="${item.coditem} + ' || ' + ${defaultcoditem}"> 564 || ? </option> </th:block> </select>

but result is...

<select id="selitems"> <option selected="selected" value="455">11/2014 - 455 || 450</option> <option selected="selected" value="450">450 || 450</option> <option selected="selected" value="452">452 || 450</option> <option selected="selected" value="457">457 || 450</option> <option selected="selected" value="453">453 || 450</option> <option selected="selected" value="454">454 || 450</option> <option selected="selected" value="451">451 || 450</option> </select>

when expected this:

<select id="selitems"> <option selected="" value="455">11/2014 - 455 || 450</option> <option selected="selected" value="450">450 || 450</option> <option selected="" value="452">452 || 450</option> <option selected="" value="457">457 || 450</option> <option selected="" value="453">453 || 450</option> <option selected="" value="454">454 || 450</option> <option selected="" value="451">451 || 450</option> </select>

so, how should compare item.coditem defaultcoditem in template set selected attribute correctly?

according thymeleaf documentation :

the standard dialect includes attributes allow set these attributes evaluating condition, if evaluated true, attribute set fixed value, , if evaluated false, attribute not set

selected 1 of them . think should write status :

th:selected="${item.coditem} eq ${defaultcoditem}"

i guess current line not work expected because non null values evaluated true (such empty string)

spring-mvc thymeleaf

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -