${xmlval} > ${ maxEachOSTime} ${xmlval} > ${ maxEachOSTime} ${xmlval} > ${ maxEachOSTime}

compare 2 variables in jelly script

381 Views Asked by At

<j:set var="maxEachOSTime" value="0" />
<j:if test="${xmlval &gt; maxEachOSTime}">
    ${xmlval} &gt; ${ 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?

2

There are 2 best solutions below

0
Azee77 On BEST ANSWER

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 &gt; intThing}">
    <j:set var="maxEachOSTime" value="${xmlval}"/>
    <j:set var="finalTotalDuration" value="${total_duration}"/>
</j:if>
7
Sercan On

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 &gt;.