Re: Short form of if..else

Daniel Dekany <[email protected]> Wed, 7 Aug 2013 17:28:59 +0200
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Tuesday, August 6, 2013, 10:56:44 PM, anjibman wrote:

> Hi All,
>
> What is the short form of
> <#if myDTO.field??>
>    ${myDTO.filed?size}
> <#else>
>    0
> <#/if>
>
> Right now I have ${myDTO.field ! "0"} which *doesn't* print size if
> myDTO.field is not NULL.

What your code really want to say is that if `field` doesn't exist,
then it should be treated like if its size was 0. So just say that in
FTL too:

  ${(myDTO.field![])?size}

Another solution is:

  ${(myDTO.field?size)!0}

but it's less telling, also it will hide the error if `myDTO` is null,
which is unintended.

-- 
Thanks,
 Daniel Dekany


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk