Details

    • Type: Wish Wish
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: GenericTools
    • Labels:
      None

      Description

      Right now, in order to check for null we have to use:

      #if ((! $var) && ("$!var" == ""))

      which is painful when you have lots of checks to do in several places.

      It would be nice either to have better null check support in velocity core or to bundle to NullTool in Velocity Tools:
      http://wiki.apache.org/velocity/NullTool

      I checked the user guide and googled around and couldn't find any simple way to check for null except using an undefined variable which I find way too magical and dangerous (what if someone defines that variable in the context).

        Activity

        Vincent Massol created issue -
        Hide
        Nathan Bubna added a comment -

        Not just any undefined variable. Use $NULL or $null. If someone with access to the context is putting in a non-null value with "NULL" or "null" as the key, you have problems. In fact, my primary objection to the NullTool is the implied/suggested key of $null. Terrible idea! Maybe an isNull(Object) method could easily be added to the ContextTool (which does have a $context.contains('var') method that is very close). But personally, i think #if( $var == $null ) is very straightforward and cleaner than $context.isNull($var).

        Show
        Nathan Bubna added a comment - Not just any undefined variable. Use $NULL or $null. If someone with access to the context is putting in a non-null value with "NULL" or "null" as the key, you have problems. In fact, my primary objection to the NullTool is the implied/suggested key of $null. Terrible idea! Maybe an isNull(Object) method could easily be added to the ContextTool (which does have a $context.contains('var') method that is very close). But personally, i think #if( $var == $null ) is very straightforward and cleaner than $context.isNull($var).
        Nathan Bubna made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Vincent Massol
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development