Mackinaw
13 years agoAdept
handling empty tags in freemarker
Hi,
I'm parsing the label attribute to a message and am encountering an error when the field is empty.
My code works when the rest response looks like this:
<response status="success">
<labels>
<label type="label" href="/labels/id/4">
<id type="int">4</id>
<text type="string">This Message's Label</text>
</label>
</labels>
</response>
where it's breakingis on a response such as this:
<response status="success">
<labels></labels>
</response>
My code looks like this:
<#assign board=rest("${selectedBlog.@href}/topics")>
<#list board.node_message_context.message.@href as id>
<#assign boardMessage=rest("${id}?restapi.response_style=view")>
<#assign labels=restadmin("/messages/id/${boardMessage.message.id}/labels").value!"">
${labels.text}
If the label is present, this works great. If it is not, I get the following error:
Expecting a string, date or number here, Expression labels.text is instead a freemarker.ext.dom.NodeListModel
Can someone suggest how can I check for this situation (empty label response) and handle it?
Thank you!
Paul