开发者

Grails - How to update a GSP after changing a select?

I have written a domain class and scaffolded the controller and the views. I've modified the list.gsp and list action a bit. To filter what's displayed, I've put a g:select tag on the pa开发者_运维技巧ge.

Whenever the value in the select is changed, the list controller is fired again and filters the data instance returned. This works like a charm.

Thing is that I can't display the changed instance; the only way I know to update the GSP is to do a window.location.reload() but that results in a re-initialization of the page. So everything is back to default.

So here is the question: how can I make my GSP pick up the changed instance data and display that?

For example, one of the selects. The returned instance is filtered though the selected month and year variables.

        <g:select id="monthSelection" from="${['Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']}" value="${inputYear}" onchange="${remoteFunction(
        action:'list', 
        params:'\'selectedYear=\' + escape(yearSelection.value) +\'&selectedMonth=\' + escape(this.value)'
        )}"
        "/>

Thanks!


Sounds like you either need to

  1. reload the whole page on month selection (passing the selected month as a parameter), or
  2. change your remoteFunction method so that it returns a template view, and set the update parameter on the remoteFunction call to specify which div on the page should get dynamically updated with the content from the returned view.

I've used option 2 in several cases where I needed an ajax update and it worked nicely.


Try out something like this :

    <g:select id="monthSelection" from="${['Jan', 'Feb', 'Mrt', 'Apr', 'Mei', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dec']}" value="${inputYear}" onchange="${remoteFunction(
            action:'list', 
            params:'\'selectedYear=\' + escape(yearSelection.value) +\'&selectedMonth=\' + escape(this.value)',
            update : 'divId'
)}"/>

Here 'divId' should contains the html portion that you needs to update after an ajax call with list action.

Like :

<div id='divId'>
.....
....
</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜