我有像这样的grails控制器动作.....
控制器:Home.groovy
def search(){
def pl=Long.valueOf(params.pl).longValue(); println pl
def mil=Long.valueOf(params.mil).longValue(); println mil
def mal=Long.valueOf(params.mal).longValue(); println mal
def mic=Long.valueOf(params.mic).longValue(); println mic
def mac=Long.valueOf(params.mac).longValue(); println mac
def mib=Long.valueOf(params.mib).longValue(); println mib
def mab=Long.valueOf(params.mab).longValue(); println mab
Type pt=Type.valueOf(params.pt); println pt
def results=Project.executeQuery("""
select new map (prt.name as name,pp.id as propertyId,pp.constructedSize as constructedSize,
prt.propertyLocation.name as location,pp.mrp as mrp,pp.landSize as landSize,
pp.propertyType.name as propertyType)
from Project prt
JOIN prt.projectProperties pp where
pp.propertyType.name=:pt and
pp.constructedSize between :mic and :mac and
pp.landSize between :mil and :mal and
pp.mrp between :mib and :mab and
prt.propertyLocation.id=:pl
""",[mic:mic,mac:mac,mil:mil,mal:mal,mib:mib,mab:mab,pl:pl,pt:pt])
println results
def customerInstance=new Customer()
render (view:'search',model:[results:results as JSON,customerInstance:customerInstance])
}
并且此操作呈现的视图仅在下面给出了错误的部分...
查看:Search.gsp
<table style="width: 50%;">
<g:each in="${results}" var="item">
<tr>
<td><div class="box shadow-outside-all" >
<input type="checkbox" name="getInterest" id="getInterest"
value="${item.propertyId}" style="float: left;" />
<b> ${item.name?.encodeAsHTML()}</b></br>
Property Type: ${item.propertyType?.encodeAsHTML()}</br>
Constructed Size:${item.constructedSize?.encodeAsHTML()}</br>
Land Size: ${item.landSize?.encodeAsHTML()}</br>
MRP: ${item.mrp?.encodeAsHTML()}</br>
Location: ${item.location?.encodeAsHTML()}</br>
</div>
</td>
</tr>
</g:each>
<br />
</table>
,错误是......
错误
No such property: propertyId for class: grails.converters.JSON. Stacktrace follows:
org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error evaluating expression [item.propertyId] on line [144]: No such property: propertyId for class: grails.converters.JSON
at E__Yogesh_development_work_client_okruti_propertyHub_grails_app_views_home_search_gsp$_run_closure2.doCall(search.gsp:144)
at E__Yogesh_development_work_client_okruti_propertyHub_grails_app_views_home_search_gsp.run(search.gsp:216)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.doFilter(GrailsAnonymousAuthenticationFilter.java:53)
at grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:49)
at grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: groovy.lang.MissingPropertyException: No such property: propertyId for class: grails.converters.JSON
at E__Yogesh_development_work_client_okruti_propertyHub_grails_app_views_home_search_gsp$_run_closure2_closure21.doCall(search.gsp:144)
... 10 more
任何帮助都会受到赞赏.....
答案 0 :(得分:0)
为什么要将结果呈现为JSON?不要将它们渲染为JSON。您的GSP期望地图/模型不是JSON结果。
从您的控制器中渲染您的结果:
render(view:'search', model:[
results:results,
customerInstance:customerInstance
])