grails - Suppose I have a list or map in controller, so how can I access them in GSP view using render method? -


def map = [name : "akshay"] def name_map = [full_name : map] //map

def list = ["c", "c++", "java"] //list
//want render above map , list gsp , want display on page

render method accepts map. in controller provide view name want render , model map containing data , can directly access model map on gsp.

def map = [name: "akshay"] def name_map = [full_name: map] //map def list = ["c", "c++", "java"] //list  render view: 'index', model: [namemap: name_map, langlist: list] 

in gsp, iterate on list:

<g:each in="${langlist}" status="index" var="lang">     ${lang} </g:each> 

and iterate on map of map:

<g:each in="${namemap}" status="index" var="fullnamemap">     ${fullnamemap.key}     <g:each in="${fullnamemap.value}" status="subindex" var="map">         ${map.key}         ${map.value}     </g:each> </g:each> 

also word of advice, if know datatype of variable in advance use datatype instead of def.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -