所以这是我的控制器中的show()方法,InsitutionList作为全局变量,但是当我想从list.gsp访问这个InsitutionList时,它不会渲染(也没有给出任何像null值的错误,我相信我正在成功地传递它。还提到下面的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>
答案 0 :(得分:1)
似乎你正在改变错误的动作或gsp。一旦你没有在“show”动作中指定视图,Grails将呈现show.gsp但你期望list.gsp上的“institutionList”。
答案 1 :(得分: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>