This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Groovy and the fly likes Ajax RemoteFunction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Ajax RemoteFunction" Watch "Ajax RemoteFunction" New topic
Author

Ajax RemoteFunction

Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
Hi all,

I have a page, and on this page I have a select box. I want that when I click on one of the choices in my select box, the selected element is send to a controller, that controller makes a GORM search, when returns it to a template which will be dynamically printed on the screen. Here is my code at the moment, actually I think the action is not even called.

Main page :


EmailController.groovy


_formSelectTemplate.gsp
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

actually I think the action is not even called.


Then you should do something to ensure that it is. Like breakpoints or log statements or println statements.

The only issue I see in your code is this...



Views are not prefixed with an underscore. Templates are, which is what you really need to be calling.



Technically, you should be geting a 404 from the server. I'd recommend a tool like Firebug if you're going to be trying to debug ajax / javascript stuff.


GenRocket - Experts at Building Test Data
Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
Yes I use Firebug and I've put a println when at the beginning of the action. Look once again ;)
And I've not seen any 404 with Firebug.
Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
Sorry for yesterday, I was in a hurry before leaving work, I didn't even thank you ;)

I've fixed the code with template. And anything I choose, or template or view (and renaming the gsp as it must be), it doesn't work.

And why should I get a 404 ?

EDIT : As newby in grails I ask the question, should I put the g:select into a formRemote or another form, or does it work if I let it alone ?

EDIT 2 : Here is the HTML code on the select get with Firebug :



As you see, there is no js event on the select.
Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
I fixed it. It's my fault, I've forgotten the comas, and I had to replace the double quotes by single ones.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Glad you figured it out. To answer your question about why you should have gotten a 404 (which you would have had you been hitting the controller) is because when you render a view grails goes and looks for a GSP. It would not have found one, so it would have returned a 404 to the browser.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

BTW, while cross-posting is a perfectly fine thing to do in order to get some answers, it would be nice if you let us know (and probably let SO know as well) that you did so.

http://stackoverflow.com/questions/7804700/grails-remoteform-ajax-doesnt-work

BeForthrightWhenCrossPostingToOtherSites
Jack Rackham
Greenhorn

Joined: Aug 03, 2011
Posts: 23
Gregg Bolinger wrote:BTW, while cross-posting is a perfectly fine thing to do in order to get some answers, it would be nice if you let us know (and probably let SO know as well) that you did so.

http://stackoverflow.com/questions/7804700/grails-remoteform-ajax-doesnt-work

BeForthrightWhenCrossPostingToOtherSites


Yes that's me. I hadn't seen this (even though no one should ignore the law), I hadn't wondered about cross-posting before. So accept my apologizes if necessary.

ANd thanks for your answer about the 404 ;)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ajax RemoteFunction
 
Similar Threads
Where are the temporary files located? Need pointers for debugging failing Ajax call/rendering
Upload a File Using jQuery
[Grails] Add form elements with javascript
Grails Application, remoteFunction with Effects
request.getAttribute returning null