Clarity

 View Only
  • 1.  Possible BUG evaluating conditions

    Posted Aug 07, 2013 05:42 AM
    Hi,

    So here i am, trying to do a simple thing like testing that a value that i get from DB is equal to 0 (taking into account possible decimals). Easy, i thought, and then this happened.

    This is the output of my test script:

    [color=#fa0202]zero...[color]

    And this is the simple script:
    <gel:script xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:core="jelly:core" xmlns:email="jelly:email"
        xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:sql="jelly:sql"
        xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
        xmlns:xog="http://www.niku.com/xog"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
       <gel:setDataSource dbId="Niku"/>
       
       <sql:query var="get_units">
    
    
      SELECT 0.5 FROM DUAL
       </sql:query>         
       <core:forEach items="${get_units.rowsByIndex}" var="v_units">
    
    
    <core:set value="${v_units[0]}" var="units"/>           
       </core:forEach> 
    
    
    <core:choose>
    
    
    <core:when test="${units== 0}">
    
    
    
    <gel:out>zero... </gel:out>
    
    
    </core:when>
    
    
    <core:otherwise>
    
    
    
    <gel:out>greater or less than 0 - otherwise</gel:out>
    
    
    </core:otherwise>
    
    </core:choose>
    </gel:script>
    Why is it giving a "zero" output when i have a 0.5 ?

    Any ideas would be appreciated,
    Thank you.


  • 2.  RE: Possible BUG evaluating conditions
    Best Answer

    Posted Aug 08, 2013 09:59 AM
    Hi,

    xelnag wrote:


    So here i am, trying to do a simple thing like testing that a value that i get from DB is equal to 0 (taking into account possible decimals). Easy, i thought, and then this happened.

    [color=#fa0202]zero...[color]

    And this is the simple script:
    ...
    
    <core:choose>
    
    
    <core:when test="${units== 0}">
    
    
    
    <gel:out>zero... </gel:out>
    
    
    </core:when>
    
    
    <core:otherwise>
    
    
    
    <gel:out>greater or less than 0 - otherwise</gel:out>
    
    
    </core:otherwise>
    
    </core:choose>
    ...
    </gel:script>
    Why is it giving a "zero" output when i have a 0.5 ?
    0 is an integer, so the units gets also casted to integer. :blink:
    If you add the ${units} to the gel:out you will notice that you get 0.5.

    Use the folowing test line instead, to make the script behave the right way:
    <core:when test="${units == [color=#f31212]0.0[color]}">

    Best regards,

    Sergiu Gavrila

    ------------------
    Clarity Add-Ons www.itdesign.de/itd-addons/
    Real Time Workload Analytics meisterplan.com


  • 3.  RE: Possible BUG evaluating conditions

    Posted Aug 09, 2013 04:25 AM
    Now i feel kinda dumb for not noticing the integer cast but yeah, did some tests and if you put 0.0 seems like the static value gets to say what will be the comparison type (integer vs float). A value of 0 will force an integer comparison while 0.0 will force a decimal one or even a '0' would force a char one, ignoring completely the type of whatever variable you actually compare against.

    Thank you Sergiu.