ajax - Grails formRemote redirects rather than to just call method -
i'm new grails , got problem g:formremote command..
i want g:textarea box send message controller , save messages. after page should updated via formremote ajax, messages appear on page.
but instead of updating page, formremote call assumes given url real link , wants me redirect (non-existing) .jsp site.
method want start called in controller tho
i tried many solutions offered in similar problems, seems problem different theirs
heres code:
<div id="history"> <g:render template="posts" collection="${ messages }" var="message" /> </div> <div class="postmessageform"> <g:formremote name="postchatmessage" url="[controller: 'meetingroom', action: 'postmessage']" update="history"> <div class="msg_box"> <g:textarea name="message" value="" style="width: 630px"/><br/> </div> <div style="float: right;"> <g:submitbutton name="send" style="width: 90px; height: 40px;"/> </div> </g:formremote> </div>
and action called in meetingroomcontroller:
def postmessage() { if (params.message != "") { def thisuser = lookupuser() def thisroom = thisuser.joinedroom def chatpost = new chatpost( message: params.message, author: thisuser ) thisroom.addtochathistory(chatpost) } // def messages = currentchathistory() // render template: 'posts', collection: messages, var: 'message'
i saw kind of approach in jeff browns twitter tutorial.
possible failures seeing:
- the out-commented render template command has ajax (when not comment thing happens template posts rendered on redirected page
- usage of both ajax , jquery (but dont believe can point because have used g: , groovy stuff , havent imported jquery lib)
- this easier remotefunction (i dont know how remotefunction work in case tho)
i hope information enough let see missing
when submit button clicked on form, data sent method listed in url parameter of formremote tag. inside method, commented out render tag outputs data gsp page in div mentioned in update tag of formremote tag.
formremote relies upon javascript library handle ajax stuff mentioned in grails documentation:
7.7.1 ajax support
by default grails ships jquery library, through plugin system provides support other frameworks such prototype, dojo:http://dojotoolkit.org/, yahoo ui:http://developer.yahoo.com/yui/ , google web toolkit. section covers grails' support ajax in general. started, add line tag of page:
can replace jquery other library supplied plugin have installed. works because of grails' support adaptive tag libraries. grails' plugin system there support number of different ajax libraries including (but not limited to):
jquery prototype dojo yui mootools
so remove in history div, uncomment 2 lines in postmessage method, , include 1 of referenced javascript libraries.
Comments
Post a Comment