Referencing Hash Values from Keys

"Shelley, Ryan" <[email protected]> Tue, 27 Oct 2009 04:45:11 +0000
Newsgroups gmane.comp.text.fmpp
Message-ID <CDD88F99FC3CE94CB8CAE5593D178A8C01DDCD11@SM-CALA-VXMB03A.swna.wdpr.disney.com>
This is a multi-part message in MIME format.

--===============3820316425475598807==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01CA56C0.44929E59"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA56C0.44929E59
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I'm new to Freemarker, but have used other templating languages in the
past.  Currently, I'm attempting to use FMPP to generate configuration
files, but having a bit of difficulty referencing hash values from keys.
Here is my TDD and sample template:

=20

TDD:

=20

{

      pools: [

            {

                  poolName: Foo

                  poolConnections: ServiceA

            },

            {

                  poolName: Bar

                  poolConnections: ServiceB

            }

      ]

}

=20

Template:

=20

This will output fine:

<#list pools as pool>

      <#assign keys =3D pool?keys >

      <#list keys as key>

            ${key} =3D ${pool[key]}

      </#list>

</#list>

=20

This will get an error on poolConnections:

<#list pools as pool>

      ${pool.poolName}

      ${pool.poolConnections}

</#list>

=20

In the first list iteration, everything is output correctly, but I have
no control over the keys.  However, the second iteration fails on
"${pool.poolConnections}" with the error:

=20

Caused by: freemarker.core.InvalidReferenceException: Expression
pool.poolConnections is undefined (notice the error is not on
pool.poolName)

=20

If I take "${pool.poolConnections}" out, it works fine (I see the value
for poolName), but I kind of need to be able to access
"poolConnections"!

=20

I've tried this with different combinations of
"${pool[poolConnections]}" and "${pool['poolConnections']}" and
"${pool.get(poolConnections)}" but none seem to be correct.  I've been
back and forth through the documentation and the examples, but none seem
to cover accessing a hash value by it's key directly.

=20

Suggestions?  Thanks!

=20

-Ryan


------_=_NextPart_001_01CA56C0.44929E59
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:x=3D"urn:schemas-microsoft-com:office:excel" =
xmlns:p=3D"urn:schemas-microsoft-com:office:powerpoint" =
xmlns:a=3D"urn:schemas-microsoft-com:office:access" =
xmlns:dt=3D"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" =
xmlns:s=3D"uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" =
xmlns:rs=3D"urn:schemas-microsoft-com:rowset" xmlns:z=3D"#RowsetSchema" =
xmlns:b=3D"urn:schemas-microsoft-com:office:publisher" =
xmlns:ss=3D"urn:schemas-microsoft-com:office:spreadsheet" =
xmlns:c=3D"urn:schemas-microsoft-com:office:component:spreadsheet" =
xmlns:odc=3D"urn:schemas-microsoft-com:office:odc" =
xmlns:oa=3D"urn:schemas-microsoft-com:office:activation" =
xmlns:html=3D"http://www.w3.org/TR/REC-html40" =
xmlns:q=3D"http://schemas.xmlsoap.org/soap/envelope/" =
xmlns:rtc=3D"http://microsoft.com/officenet/conferencing" =
xmlns:D=3D"DAV:" xmlns:Repl=3D"http://schemas.microsoft.com/repl/" =
xmlns:mt=3D"http://schemas.microsoft.com/sharepoint/soap/meetings/" =
xmlns:x2=3D"http://schemas.microsoft.com/office/excel/2003/xml" =
xmlns:ppda=3D"http://www.passport.com/NameSpace.xsd" =
xmlns:ois=3D"http://schemas.microsoft.com/sharepoint/soap/ois/" =
xmlns:dir=3D"http://schemas.microsoft.com/sharepoint/soap/directory/" =
xmlns:ds=3D"http://www.w3.org/2000/09/xmldsig#" =
xmlns:dsp=3D"http://schemas.microsoft.com/sharepoint/dsp" =
xmlns:udc=3D"http://schemas.microsoft.com/data/udc" =
xmlns:xsd=3D"http://www.w3.org/2001/XMLSchema" =
xmlns:sub=3D"http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/"=
 xmlns:ec=3D"http://www.w3.org/2001/04/xmlenc#" =
xmlns:sp=3D"http://schemas.microsoft.com/sharepoint/" =
xmlns:sps=3D"http://schemas.microsoft.com/sharepoint/soap/" =
xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance" =
xmlns:udcs=3D"http://schemas.microsoft.com/data/udc/soap" =
xmlns:udcxf=3D"http://schemas.microsoft.com/data/udc/xmlfile" =
xmlns:udcp2p=3D"http://schemas.microsoft.com/data/udc/parttopart" =
xmlns:wf=3D"http://schemas.microsoft.com/sharepoint/soap/workflow/" =
xmlns:dsss=3D"http://schemas.microsoft.com/office/2006/digsig-setup" =
xmlns:dssi=3D"http://schemas.microsoft.com/office/2006/digsig" =
xmlns:mdssi=3D"http://schemas.openxmlformats.org/package/2006/digital-sig=
nature" =
xmlns:mver=3D"http://schemas.openxmlformats.org/markup-compatibility/2006=
" xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns:mrels=3D"http://schemas.openxmlformats.org/package/2006/relationshi=
ps" xmlns:spwp=3D"http://microsoft.com/sharepoint/webpartpages" =
xmlns:ex12t=3D"http://schemas.microsoft.com/exchange/services/2006/types"=
 =
xmlns:ex12m=3D"http://schemas.microsoft.com/exchange/services/2006/messag=
es" =
xmlns:pptsl=3D"http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/=
" =
xmlns:spsl=3D"http://microsoft.com/webservices/SharePointPortalServer/Pub=
lishedLinksService" xmlns:Z=3D"urn:schemas-microsoft-com:" =
xmlns:st=3D"&#1;" xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
	{page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext=3D"edit">
  <o:idmap v:ext=3D"edit" data=3D"1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal>I&#8217;m new to Freemarker, but have used other =
templating
languages in the past.&nbsp; Currently, I&#8217;m attempting to use FMPP =
to
generate configuration files, but having a bit of difficulty referencing =
hash values
from keys.&nbsp; Here is my TDD and sample template:<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>TDD:<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New"'>{<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span
style=3D'color:black'>pools</span>: [<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poolName:
Foo<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poolConnections:
ServiceA<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
},<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
{<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poolName:
Bar<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; poolConnections:
ServiceB<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
]<o:p></o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'>}<o:p></o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p>&nbsp;</o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'>Template:<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'><o:p>&nbsp;</o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>This will output =
fine:<o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&lt;</span><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:#3F7F5F'>#list pools as =
pool&gt;</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#3F7F5F'>#assign keys =3D
pool?keys &gt;</span><span =
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;</span><span
style=3D'font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>#list =
keys as
key&gt;</span><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier =
New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp; ${key}
=3D </span><span style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#2A00FF'>${pool[key]}</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&lt;/</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#3F7F5F'>#list&gt;</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:black'>&lt;/</span><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:#3F7F5F'>#list&gt;<o:p></o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:#3F7F5F'><o:p>&nbsp;</o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:black'>This will get an error on poolConnections:</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New";color:#3F7F5F'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&lt;</span><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:#3F7F5F'>#list pools as =
pool&gt;</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
${pool.poolName}</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal style=3D'text-autospace:none'><span =
style=3D'font-size:10.0pt;
font-family:"Courier New";color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
${pool.poolConnections}</span><span
style=3D'font-size:10.0pt;font-family:"Courier =
New"'><o:p></o:p></span></p>

<p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:black'>&lt;/</span><span =
style=3D'font-size:10.0pt;font-family:"Courier New";
color:#3F7F5F'>#list&gt;<o:p></o:p></span></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>In the first list iteration, everything is output =
correctly,
but I have no control over the keys.&nbsp; However, the second iteration =
fails
on &#8220;${pool.poolConnections}&#8221; with the error:<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>Caused by: =
freemarker.core.InvalidReferenceException:
Expression pool.poolConnections is undefined (notice the error is not on
pool.poolName)<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>If I take &#8220;${pool.poolConnections}&#8221; =
out, it
works fine (I see the value for poolName), but I kind of need to be able =
to access
&#8220;poolConnections&#8221;!<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>I&#8217;ve tried this with different combinations =
of &#8220;${pool[poolConnections]}&#8221;
and &#8220;${pool[&#8216;poolConnections&#8217;]}&#8221; and =
&#8220;${pool.get(poolConnections)}&#8221;
but none seem to be correct. &nbsp;I&#8217;ve been back and forth =
through the
documentation and the examples, but none seem to cover accessing a hash =
value
by it&#8217;s key directly.<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>Suggestions?&nbsp; Thanks!<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal>-Ryan<o:p></o:p></p>

</div>

</body>

</html>

------_=_NextPart_001_01CA56C0.44929E59--


--===============3820316425475598807==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
--===============3820316425475598807==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
fmpp-open mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fmpp-open

--===============3820316425475598807==--