Hossain Cyrus
Hossain Cyrus

Reputation: 65

Cannot access HashMap inside view template of Play-1.2

I'm trying to get the value of a template rendered in a string.

Here's my controller code:

Template template = TemplateLoader.load("app/views/Reports/dummy.html");    
Map<String, Object> map = new HashMap<String, Object>();
map.put("dummy key", "dummy value");
play.Logger.debug("rendered template - " + template.render(map));

And below is how i'm trying to access the map in my view

#{list items:map.keySet(), as:'key'}
   //some manipulation      
#{/list}

But when the action is invoked the error below is shown:

Execution error occurred in template /app/views/Reports/dummy.html. Exception raised was NullPointerException : Cannot invoke method keySet() on null object.

I can't figure out what went wrong. I'm using 1.2.5.3 of play framework and groovy template engine.

Upvotes: 0

Views: 275

Answers (1)

TeTeT
TeTeT

Reputation: 2094

You cannot access the map itself you give to the template engine but the keys within:

map.put("key", "value");

In the template you can then access it via

${key}

Upvotes: 1

Related Questions