0

所以这是我的控制器中的 show() 方法,其中 InsitutionList 作为全局变量,但是当我想从 list.gsp 访问这个 InsitutionList 时,它没有呈现(也没有给出任何错误,如空值,从那里我相信我正在传递它成功)任何东西。还提到了下面的 gsp 片段。

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]

}

尝试了不同的东西,没有运气:

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)像这样更简单也不起作用

            <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>
4

2 回答 2

1

看来您正在更改错误的操作或 gsp。只要您没有在“show”操作中指定视图,Grails 就会呈现 show.gsp,但您希望 list.gsp 上有“institutionList”。

于 2013-01-15T22:59:47.110 回答
0

似乎那institutionList不是Map一个List

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

好像

Map.putAt(Object key, Object value)

什么显示带有以下代码的 gsp?

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

还是使用 gsp 中最简单的代码?

<h1>${institutionList}</h1>
于 2013-01-16T00:47:16.690 回答