Bug 780625 (SOA-3065)

Summary: Freemarker expressions not working on DomModelCreator created fragments
Product: [JBoss] JBoss Enterprise SOA Platform 5 Reporter: Martin Weiler <mweiler>
Component: JBossESBAssignee: Tom Fennelly <tom.fennelly>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: 5.1.0 GACC: tom.fennelly
Target Milestone: ---   
Target Release: 5.2.0.ER5   
Hardware: Unspecified   
OS: Unspecified   
URL: http://jira.jboss.org/jira/browse/SOA-3065
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-11-04 12:54:39 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Martin Weiler 2011-05-13 09:56:31 UTC
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/*" />
	</jb:bean>

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:

      <response>
         <item>
            <titel>Prof. Dr. med.</titel>
            <anrede>Herr</anrede>
            <vorname>Max</vorname>
            <nachname>Mustermann</nachname>
         </item>
         <item>
            <personalnummer>124545</personalnummer>
            <titel>Dr.</titel>
            <anrede>Mr</anrede>
            <vorname>John</vorname>
            <nachname>Doe</nachname>
         </item>     
      </response>

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 20:30:28 UTC
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 20:07:07 UTC
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 11:47:37 UTC
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 13:07:08 UTC
Ooops... sorry... shouldn't have closed that

Comment 5 tcunning 2011-10-07 13:11:14 UTC
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 12:54:39 UTC
No change, no verification needed.