Thymeleaf switch on integer, case greater than

ExplodingTiger

This is probably an easy question but I can't seem to think of an answer to it.

I have this simple Thymeleaf code:

<ul data-th-switch="${someVar}">
    <li data-th-case="${gt 6}">someVar is greater than 6.</li>
    <li data-th-case="*">Default case.</li>
</ul>

I get an error on data-th-case="${gt 6}". Is there a way to do this in Thymeleaf?

Thanks in advance.

Lachezar Balev

The syntax is wrong indeed. Details.

A correct syntax one be "${someVar} gt 6" but of course, it will not work correctly, although the template will render. That is because ${someVar} evaluates to 12 (for example) while ${someVar} gt 6 evaluates to true. These are not equal.

If you enable the ThyemeLeaf trace you will see how thymeleaf will interpret this:

o.t.s.expression.GreaterThanExpression   : Evaluating GREATER THAN expression: "${someVar} > 6". Left is "12", right is "6". Result is "true"
o.t.s.expression.EqualsExpression        : Evaluating EQUALS expression: "${someVar} == (${someVar} > 6)". Left is "12", right is "true". Result is "false"

Depending on the logic which you want to implement you may come to very different solutions - e.g. from putting a gadget in your model to implementing if-else logic. Check this question for some more ideas.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Thymeleaf switch case on integer

From Dev

Greater than in SQL CASE statement

From Dev

Greater than in SQL CASE statement

From Java

Lesser than or greater than in Swift switch statement

From Dev

Use R switch for less than or greater than?

From Dev

why string is greater or less than the integer?

From Dev

How to find the elements greater than integer

From Dev

Using .where condition for results greater than an integer

From Dev

Javascript switch greater than / less than operators not working

From Dev

if integer is greater than x but less than y (Swift)

From Dev

OverflowError: signed integer is greater than maximum when parsing date in python

From Dev

Laravel: validate an integer field that needs to be greater than another

From Dev

php - Split an associative array with value greater than some integer

From Dev

T-SQL Date difference greater than an integer

From Dev

Longest Subsequence where an integer in the output is 5 times greater than the previous

From Dev

Find the minimum set of integers whose sum is greater than a given integer

From Dev

Random integer with specific range: values are getting greater than max value

From Dev

Validating whether raw input is an integer and greater than zero simultaneously in Python

From Dev

SQL: Greater than or equal to in where clause based on case condition?

From Dev

How use Greater Than 0 (>0) within Case in Sql Server?

From Dev

Find smallest integer greater or equal than x (positive integer) multiple of z (positive integer, probably power of 2)

From Java

Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

From Dev

how to convert integer variable having values greater than the integer size to string in talend

From Dev

select 10 greater than and 10 lesser than an integer value in db2.

From Dev

Replace multiple switch case when checking for multiple integer ranges

From Dev

what happens if we input a character in a switch case where an integer is required

From Dev

SQL 'CASE WHEN x' vs. 'CASE x WHEN' with greater-than condition?

From Dev

Greater than > Less than < inside thymeleaf javascript... Error: The content of elements must consist of well-formed character data or markup

From Dev

How can I switch to window number greater than 10 or higher in Ratpoison?

Related Related

  1. 1

    Thymeleaf switch case on integer

  2. 2

    Greater than in SQL CASE statement

  3. 3

    Greater than in SQL CASE statement

  4. 4

    Lesser than or greater than in Swift switch statement

  5. 5

    Use R switch for less than or greater than?

  6. 6

    why string is greater or less than the integer?

  7. 7

    How to find the elements greater than integer

  8. 8

    Using .where condition for results greater than an integer

  9. 9

    Javascript switch greater than / less than operators not working

  10. 10

    if integer is greater than x but less than y (Swift)

  11. 11

    OverflowError: signed integer is greater than maximum when parsing date in python

  12. 12

    Laravel: validate an integer field that needs to be greater than another

  13. 13

    php - Split an associative array with value greater than some integer

  14. 14

    T-SQL Date difference greater than an integer

  15. 15

    Longest Subsequence where an integer in the output is 5 times greater than the previous

  16. 16

    Find the minimum set of integers whose sum is greater than a given integer

  17. 17

    Random integer with specific range: values are getting greater than max value

  18. 18

    Validating whether raw input is an integer and greater than zero simultaneously in Python

  19. 19

    SQL: Greater than or equal to in where clause based on case condition?

  20. 20

    How use Greater Than 0 (>0) within Case in Sql Server?

  21. 21

    Find smallest integer greater or equal than x (positive integer) multiple of z (positive integer, probably power of 2)

  22. 22

    Given an integer N. What is the smallest integer greater than N that only has 0 or 1 as its digits?

  23. 23

    how to convert integer variable having values greater than the integer size to string in talend

  24. 24

    select 10 greater than and 10 lesser than an integer value in db2.

  25. 25

    Replace multiple switch case when checking for multiple integer ranges

  26. 26

    what happens if we input a character in a switch case where an integer is required

  27. 27

    SQL 'CASE WHEN x' vs. 'CASE x WHEN' with greater-than condition?

  28. 28

    Greater than > Less than < inside thymeleaf javascript... Error: The content of elements must consist of well-formed character data or markup

  29. 29

    How can I switch to window number greater than 10 or higher in Ratpoison?

HotTag

Archive