0

The following is the antlr string template code which I am struggling over. I have a property Item.AmountPaid which might have data (or) could be blank sometimes. So when it has no data I should show Disabled TR and hide Enabled TR and vice-versa. The problem I am facing is whether the property is having data or not, only IF statement is executing every time. Please let me know your valuable suggestions. Thank You for your help!

       $ 
       orders: { Item|
       $if(Item.AmountPaid)$
       <tr class="Enabled">
         <td>$Item.AmountPaid$</td>
         <td>$Item.Name$</td>
         <td>$Item.City$</td>
       </tr>

      $else$
        <tr class="Disabled">
          <td>$Item.AmountPaid$</td>
          <td>$Item.Name$</td>
          <td>$Item.City$</td>
        </tr>
      $endif$
      }
      $
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
Bhargav
  • 124
  • 6
  • 19
  • StringTemplates is not related to ANTLR at all. ST is a standalone lib used by ANTLR. – Mike Lischke Sep 02 '16 at 07:58
  • What data type is `AmountPaid`? `if(item)` works fine for me if the item is a boolean type. I believe ST can only test for a null value otherwise, not an empty one. – Mike Lischke Sep 02 '16 at 08:03
  • Hi Mike, Thank You for you response. You are rite, ST is testing either null (or) non-empty values only. AmountPaid is of string datatype and we are getting empty values in it sometimes. But after passing null values to this string property instead of empty values {which only struck to me after your comment :) }, it worked! Thanks again! – Bhargav Sep 03 '16 at 11:26
  • Ok, then let me give you a proper answer which you can accept. – Mike Lischke Sep 03 '16 at 11:51

1 Answers1

1

The check in an if(expression) clause only works on boolean, null or non-empty values, but not e.g. for empty strings. So make sure the used expression is one of those constructs.

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181