'compare 2 variables in jelly script
<j:set var="maxEachOSTime" value="0" />
<j:if test="${xmlval > maxEachOSTime}">
${xmlval} > ${ maxEachOSTime}
<j:set var="maxEachOSTime" value="${xmlval}"/>
<j:set var="finalTotalDuration" value="${total_duration}"/>
</j:if>
if ${xmlval} is compared with a number ( 1, 200, etc) it works. But when compared with ${eachMaxOSTime} it doesnt work. (condition is always working as true) .intValue() also didnt help. What is the solution for this?
Solution 1:[1]
This is what that finally helped me in my specific use case.
xmlval is variable which has integer value by reading from xml file
maxEachOSTime var was set as string by default via <j:set>
Converted that into float and used its intValue()
Earlier intValue() was not working as String didnt have attribute intValue, hence the if condition was getting skipped.
This can be improvised by working directly into integers
<j:new className="java.lang.Float" var="tempFloat">
<j:arg value="${maxEachOSTime}" type="float"/>
</j:new>
<j:set var="intThing" value="${tempFloat.intValue()}"/>
<j:if test="${xmlval > intThing}">
<j:set var="maxEachOSTime" value="${xmlval}"/>
<j:set var="finalTotalDuration" value="${total_duration}"/>
</j:if>
Solution 2:[2]
The following structure is used to define a string
variable with Jelly script:
<j:set var="stringVariable" value="This is a string!"/>
<j:set var="maxEachOSTime" value="0"/>
Therefore, the type of the maxEachOSTime
variable is string
. You are trying to equate an integer
on the left side of the equation with a string
using the escape character >
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Azee77 |
Solution 2 |