Trying to get count and value on same line

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Trying to get count and value on same line

steppinrazor
I am using "th:each" but I can't seem to get the count and value on the same line -- I get a parse exception

<ol th:each="fn,fnStat : ${friends}">
    <li th:text="${fnStat.count fn}"></li>
</ol>


Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

eiryu
try this
<li th:text="${fnStat.count} + ${fn}"></li>
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

steppinrazor
That didn't work, this is what I have:

<ol th:each="fn,fnStat : ${friends}">
    <li th:text="${fnStat.count} + ${fn}"></li>
</ol>

This is the stacktrace:

thyme_leaf_stack.txt
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

Zemi
Administrator
Hello,

that error comes from the first syntax you wrote, please try again.

You could also use several tags:

<ol th:each="fn,fnStat : ${friends}">
    <li>
        < span th:text="${fnStat.count}">3</ span>
        < span th:text="${fn}">Peter</ span>
    </li>
</ol>
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

steppinrazor
I see the alternative suggested by using 2  elements but does this mean that it can't be done like this:

<ol th:each="fn,fnStat : ${friends}">

    <li th:text="${fnStat.count} + ${fn}"></li>
</ol>

This does through the stacktrace I showed previously, it's like the 2 can't co-exist in the same "execution" space.
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

Emanuel
Administrator
Maybe the problem is the addition?  count is an int, so the operation will become an addition, which means you're trying to add an int to an Object, which you can't do in Java.

So, alternatives will be to turn that addition into a string concatenation by making the int a String, or by introducing a String to the operation, eg:

<li th:text="${fnStat.count} + '' + ${fn}"></li>    <!-- That is 2 single quotes, not 1 double quote -->

Or:

<li th:text="${#strings.toString(fnStat.count)} + ${fn}"></li>
Reply | Threaded
Open this post in threaded view
|

Re: Trying to get count and value on same line

steppinrazor
It all works now thanks guys