Handling of optional data tree

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
tim
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Handling of optional data tree

tim
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!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Handling of optional data tree

Boomerific

Tim,

Perhaps you can check for the model data's existance first?
<#if (p.share??)> ... </#if>

Darryl

On Feb 11, 2015 10:56 AM, "tim" <[hidden email]> 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
[hidden email]
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/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Handling of optional data tree

Daniel Dekany
In reply to this post by tim
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
> [hidden email]
> 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/
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Loading...