0

So this is my show() method in my controller with InsitutionList as a global variable but when I want to access this InsitutionList from list.gsp it is not rendering (also not giving any errors like null value, from there I believe i am passing it successfully) anything. Also mentioning the gsp snippet below.

def show(Long id){
    def tacticalIndustryCodeInstance = TacticalIndustryCode.get(id);
    def query = Institution.where { idParam ->
        idInstitution == idParam    
    }   
    def institution = query.find(id)
    if(!institution){
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'institution.label', default: 'Institution'), id])
        redirect(action: "list")
        return
    }

    institutionList.putAt(institution.getLongName(), tacticalIndustryCodeInstance)

    if(!tacticalIndustryCodeInstance){
        flash.message = message(code: 'default.not.found.message', args: [message(code: 'tacticalIndustryCode.label', default: 'TacticalIndustryCode'), id])        
        redirect(action: "list")
        return 
    }       
    [tacticalIndustryCodeInstance: tacticalIndustryCodeInstance, institutionList: institutionList]

}

tried different things, no luck:

1)

                    <td><g:link action="show" id="${tacticalIndustryCodeInstance.id}">${fieldValue(bean: tacticalIndustryCodeInstance, field: "id")}</g:link></td>

                    <td>${fieldValue(bean: tacticalIndustryCodeInstance, field: "industrySector")}</td>

                    <td>${Institution.executeQuery("Select longName from Institution where idInstitution = :id?",[id : $(fieldValue(bean: tacticalIndustryCodeInstance, field: "id"))])}</td>   
                </tr>
            </g:each>

2) Even simpler like this also not working

            <g:each in="${institutionList}" var="institutionListInstance">
                <td>${fieldValue(bean: institutionList, field: "longName")}</td>
            </g:each>

3)

<table id="tacticalIndustryCodeTable" class="center">
<thead>
                    <tr>                    
                        <g:sortableColumn property="id" title="${message(code: 'tacticalIndustryCode.id.label', default: 'Institution Id')}" />

                        <g:sortableColumn property="industrySector" title="${message(code: 'tacticalIndustryCode.industrySector.label', default: 'industrySector')}" />

                        <g:sortableColumn property="longName" title="${message(code: 'institution.longName.label', default: 'longName')}" />

                    </tr>
                </thead>
                <tbody>
                <g:each in="${institutionList}" var="institutionListInstance">
                    <td>${institutionListInstance.key}</td>
                    <g:each in="${institutionListInstance.value}" var="item">
                        <td>${item.id}</td>
                        <td>${item.industrysector}</td>
                </g:each>
                </tbody>
            </table>
user1981882
  • 21
  • 1
  • 3

2 Answers2

1

It seems that you're changing wrong action or gsp. As soon as you haven't specified view in "show" action Grails will render show.gsp but you expecting "institutionList" on the list.gsp.

Sergei Shushkevich
  • 1,356
  • 10
  • 14
  • I believe that's not the case as I can edit views from there....I believe it is with my gsp...I posted my detailed gsp table in option 3 in the original question.... – user1981882 Jan 16 '13 at 15:33
  • I agree with Sergei. Your controller code doesn't show any redirect or render to `list.gsp with` a model containing `institutionList`. Have you tried a `render(view: "list", model: [tacticalIndustryCodeInstance: tacticalIndustryCodeInstance, institutionList: institutionList])` ? – Grooveek Jan 16 '13 at 16:22
0

It seems that institutionList is a Map not a List

institutionList.putAt(institution.getLongName(), tacticalIndustryCodeInstance)

looks like

Map.putAt(Object key, Object value)

What displays the gsp with following code ?

<g:each in="${institutionList}" var="institutionListInstance">
    <td>${institutionListInstance}</td>
</g:each>

or with the simplest code in the gsp ?

<h1>${institutionList}</h1>
Isammoc
  • 883
  • 5
  • 20
  • Hi Isammoc...thanks for replying....I tried that before to just pass it as List...but that did not work..both of the options are not rendering anything...I tried other options like 1)Do a GORM query from gsp...2)Tried with different datatypes in the map...3)tried with encodeAsHTML() for properties...no luck.....I think it is something wrong I am doing with the gsp.......I am posting my more of my gsp below.... – user1981882 Jan 16 '13 at 15:18
  • I posted my gsp in the original question as option 3 – user1981882 Jan 16 '13 at 15:27
  • What result do you have ? Why `institutionList` is global ? Did you tried to `println` or `log` your variable in the controller ? – Isammoc Jan 16 '13 at 19:57