Re: Handling missing node values with NodeModel
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
I recommend reading this:
http://freemarker.org/docs/xgui_imperative_learn.html
It answers this question among others. Anyway, you could do it like
this:
${.vars["com.acme.Travel"].checkIn[0]!}
The relevant change I did here is the adding of [0]; the others are
just aesthetical. You see, the result of the XPath query exists even
if it's an empty node list, so what you want to know if it has a 1st
element.
Tuesday, June 21, 2011, 3:26:15 PM, Tom Fennelly wrote:
> Hi.
>
> I'm using a NodeModel and was wondering how missing nodes can be
> handled? I'm looking for the equivalent of the
> unsafe_expr!default_expr notation
> (http://freemarker.sourceforge.net/docs/dgui_template_exp.html#dgui_template_exp_missing),
> but something that works for NodeModels (the default did not work for me).
>
> BTW.. the template's in question use the .vars syntax in the
> expressions. So, when I do the following I get an exception -
> ${.vars["com.acme.Travel"]["checkIn"]!""}. The exception is...
> Expecting a string, date or number here, Expression
> .vars["com.acme.Travel"]["checkIn"]!"" is instead a freemarker.ext.dom.NodeListModel
> The problematic instruction:
> ----------
> ==> ${.vars["com.acme.Travel"]["checkIn"]!""} [on line 3,
> column 19 in free-marker-template]
> ----------
>
> Java backtrace for programmers:
> ----------
> freemarker.core.NonStringException: Error on line 3, column 21 in free-marker-template
>
> Thanks in advance.
>
> T.
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev