Access the data model from a TemplateDirectiveModel directive....

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Access the data model from a TemplateDirectiveModel directive....

mike00000888
Hi,

Trying to access a var in my data model from a directive that implements TemplateDirectiveModel.

 I am trying the following but getting a null pointer.

TemplateHashModel xxx = env.getDataModel();
TemplateModel yyy = xxx.get("customerProfile.customerId");
String zzz =((TemplateScalarModel) yyy).getAsString();

To verify, ${customerProfile.customerId} works and contains a value when used inside the template..

Much thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Access the data model from a TemplateDirectiveModel directive....

Daniel Dekany
Tuesday, January 25, 2011, 6:40:16 AM, mike00000888 wrote:

>
> Hi,
>
> Trying to access a var in my data model from a directive that implements
> TemplateDirectiveModel.
>
>  I am trying the following but getting a null pointer.
>
> TemplateHashModel xxx = env.getDataModel();
> TemplateModel yyy = xxx.get("customerProfile.customerId");
> String zzz =((TemplateScalarModel) yyy).getAsString();
>
> To verify, ${customerProfile.customerId} works and contains a value when
> used inside the template..

TemplateHashModel.get just gets a variable be name, it doesn't
evaluate its parameter an expression. So you should write
((TemplateHashModel) xxx.get("customerProfile")).get("customerID")

> Much thanks.

--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
FreeMarker-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-devel