Reloading only a gsp inside a div of another gsp
I have one gsp page say search.gsp which has a div called 'ResultContentAsFacets'. div shows contents of another gsp. This another gsp is named subSearch.gsp. Now in this page i have a link which calls action subSearch so that it reloads the subsearch.gsp. But the problem is that it reloads the search.gsp too. What should i do??
User tim_yates is basically right, but you'll probably need formRemote instead of remoteLink.
Basically you'll have in search.gsp (taken from the documentation: http://grails.org/doc/latest/ref/Tags/formRemote.html with some changes)
<g:formRemote name="search"
update="ResultContentAsFacets"
method="GET"
url="[controller: 'changeThis', action: 'subSearch']">
<!-- your input/ search fields -->
</g:formRemote>
<div id="ResultContentAsFacets">
<!-- this div is updated with the result of the submit -->
<!-- you may already render subSearch.gsp on first pageload here.
Just pass all entries to the view in your search action -->
</div>
In your "ChangeThisController" create an action subSearch that performs the actual search
But instead of returning the result, you just render the template (subSearch.gsp):
def subSearch() {
// perform search and store collection in variable called "result"
// (change naming at your will)
render template: 'subSearch' model: [result: result]
}
Your div whit id="ResultContentAsFacets" will be updated, wihtout reloading the whole page
My example does not handle error cases or users that have javascript turned off in their browsers. And there's some more stuff to do if you want pagination in your search result... but it's possible. I'm also not sure if you have to include jquery or do <r:require module="jquery">
to use the <g:formRemote>
tag. Look it up in the documentation. Hope this helps...
上一篇: GSP渲染非常缓慢