Re: Handling of optional data tree
Daniel Dekany <[email protected]> Wed, 11 Feb 2015 20:20:12 +0100
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
The syntax for what you want is:
(p.share.currency)!
That is, by default ! only guards the last step, but with parenthesis
it guards the whole expression inside.
Also, you should update FreeMarker. 2.3.21 already explains this in
the error message.
--
Thanks,
Daniel Dekany
Wednesday, February 11, 2015, 4:49:04 PM, tim wrote:
> Hi,
>
> I have a data model of this kind:
>
> contract
> +contractParties
> +contractParty
> ++share
> +++amount
> +++currency
> ...
>
> I want to display amount and share for each contract party:
> <#list contract[0].contractParties.contractParty as p>
> Amount: ${p.share.amount!}
> Share: ${p.share.currency!}
> </#list>
>
> list creates a sequence and that's fine. If there is no contract party, this
> will just be omitted -> fine.
> But then I want to access amount anf currency of the share. This works if
> there is a share. It does not work if there is no share, though. If share is
> null/empty/missing, it creates an error no matter what I do. I tried
> ${p.share[0].currency!} and ${p.share[0]!.currency!}, but it does not work
> if share is undefined.
>
> Is it possible to either
> - turn off error handling for missing data model fractions or
> - ignore missing paths
> ?
>
> Thanks for your feedback!
>
>
>
> --
> View this message in context:
> http://freemarker.624813.n4.nabble.com/Handling-of-optional-data-tree-tp4655366.html
> Sent from the freemarker-user mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> FreeMarker-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/