javagrailsgsp

gsp link to put named parameters and map in the same params attribute


I am getting problem in adding the named argument and map in the same params attribute in g:link.

I can put named argument such as:

<g:link action="action" controller="controller" params='[hello:"hello",world:"world"]'>test</g:link>

or I can make the map in the controller and use that in gsp link params such as:

<g:link action="action" controller="controller" params='${testParam}'>test</g:link>

This both form the link in proper manner. But now I want to use both ways in the same link inside params attribute such as:

<g:link action="action" controller="controller" params='${testMapParam},[hello:"hello",world:"world"]'>test</g:link>

I am unable to do in this way. This don't make the proper link. Is there a way to do this?


Solution

  • Sometimes you really can't beat simplicty:

    def test() {
        def map1=['a':1]
        def map2=['a2':2]
    
        def map3=map1+map2
        println "000 ${map3} vs ${params}"
    
        render  view:'test', model:[map1:map1,map2:map2]
    }
    

    Passing the maps to the view gsp:

       <g:set var="map6" value="${[hello1:'hello2',world1:'world2'] }"/>
    <g:set var="currentParams" value="${params}"/>
    ${map1 } ${map6}
    <g:link action="test" controller="test" params="${map1+map6+map2+currentParams}">test</g:link>
    

    Shows this when I click on link {a=1} {hello1=hello2, world1=world2} test

    My url upon clicking is:

    /test?a=1&hello1=hello2&world1=world2&a2=2&hello=hello&world=world
    000 [a:1, a2:2] vs [hello:hello, a:1, a2:2, world1:world2, hello1:hello2, world:world, action:test, controller:test]
    

    What you are trying to do ? no