hari
hari

Reputation: 619

playframework - setting a list parameter in a custom select tag

I have some repetitive select tags in my html therefore I want to create a custom select tag in play which will take as a parameter the name attribute of select (which can be done easily) and a list object through which I create option tags dynamically.

Basically I want to do something like this

////// custom tag stored in FormSelect.html///////
<select name="${_selectName}">
   #{list ${_options}, as: 't'}
      <option value="${t.Description}"> ${t.Description} </option> 
   #{/list}
</select>

///////calling the custom tag from another html file//////////
Type:
#{FormSelect selectName:'typ', options:types /}
Region:
#{FormSelect selectName:'reg', options:regions /}

types and regions variables are Vector and are forwarded from controller. I want ${_options} at select tag (inside #{list}) to take the values of types and regions

When I excecute the above code I get this exception

Template execution error 

Execution error occured in template /app/views/tags/FormSelect.html. Exception raised  was MissingMethodException : No signature of method: Template_1002.$() is applicable for argument types: (Template_1002$_run_closure1_closure2) values: [Template_1002$_run_closure1_closure2@127a1d8] Possible solutions: _(java.lang.String), is(java.lang.Object), run(), run(), any(), get(java.lang.String). 


In /app/views/tags/FormSelect.html (around line 2)

1: <select name="${_selectName}">
2:     #{list ${_options}, as: 't'}
3:        <option value="${t.Description}"> ${t.Description} </option> 
4:     #{/list}
5: </select>

thx in advance

Upvotes: 2

Views: 1553

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

Instead of

#{list ${_options}, as: 't'}
      <option value="${t.Description}"> ${t.Description} </option> 
   #{/list}

use:

#{list items:_options, as: 't'}
      <option value="${t.Description}"> ${t.Description} </option> 
#{/list}

That should solve your current error.

Upvotes: 3

Related Questions