Bug 780625 - (SOA-3065) Freemarker expressions not working on DomModelCreator created fragments
Freemarker expressions not working on DomModelCreator created fragments
Product: JBoss Enterprise SOA Platform 5
Classification: JBoss
Component: JBossESB (Show other bugs)
5.1.0 GA
Unspecified Unspecified
high Severity high
: ---
: 5.2.0.ER5
Assigned To: Tom Fennelly
Depends On:
  Show dependency treegraph
Reported: 2011-05-13 05:56 EDT by Martin Weiler
Modified: 2011-11-04 08:54 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2011-11-04 08:54:39 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

External Trackers
Tracker ID Priority Status Summary Last Updated
JBoss Issue Tracker SOA-3065 None None None Never

  None (edit)
Description Martin Weiler 2011-05-13 05:56:31 EDT
Help Desk Ticket Reference: https://na7.salesforce.com/500A0000007ASa2
Workaround: Workaround Exists
Workaround Description: Use Java binding with a HashMap instead of using the DomModelCreator:

	<jb:bean beanId="item" class="java.util.HashMap" createOnElement="response/item">
		<jb:value data="response/item/*" />

Then, use the 'unsafe_expr!default_expr' (${item.personalnummer!"not available"}) syntax inside the Freemarker template. 
project_key: SOA

Let's suppose we have the following input document:

            <titel>Prof. Dr. med.</titel>

processed by a DomModelCreator on the 'item' element, and then passed to a Freemarker template. Inside the freemarker template the ${item.xxx} syntax is used. This fails for the 'personalnummer' element here, as it is missing on the first record.

Using ${item.personalnummer!"not available"}, as shown in the Freemarker docs [1], fails with the following error:

  Caused by: freemarker.core.NonStringException: Error on line 2, column 3 in personFrag.ftl
  Expecting a string, date or number here, Expression item.anrede is instead a freemarker.ext.dom.NodeListModel

[1] http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_missing_default
Comment 1 Tom Fennelly 2011-06-30 16:30:28 EDT
I think there actually is a solution to this within FreeMarker, but it's a bit ugly.  Read this... http://freemarker.org/docs/xgui_imperative_learn.html

Anyway.. the freemarker syntax for nodemodel would be something like...

${item.personalnummer[0]!"not available"}

Note the [0]
Comment 2 Anne-Louise Tangring 2011-07-11 16:07:07 EDT
Candiate, not commited. Can we deal with it in Smooks? Or if it requires an update to freemarker, then we need to punt. Tom C to investigate
Comment 3 Tom Fennelly 2011-09-08 07:47:37 EDT
This can not be fixed within Smooks.  It's a FreeMarker issue.  There is a workaround however (see comment above).
Comment 4 Tom Fennelly 2011-10-07 09:07:08 EDT
Ooops... sorry... shouldn't have closed that
Comment 5 tcunning 2011-10-07 09:11:14 EDT
No ESB change or Freemarker change required here, the resolution should be to follow the steps outlined by Tom F and the workaround.
Comment 6 Martin Vecera 2011-11-04 08:54:39 EDT
No change, no verification needed.

Note You need to log in before you can comment on or make changes to this bug.