|
Hello guys,
what i have to tell the controller that he just save the Textfields into the Database but without any redirection when i click on the Save button? The only thing what should happen is that it will be saved in the Database and nothing more. This is the standard save Controller class, what do I have to change? def save() { def myInstance = new Myparams) if (!myInstance.save(flush: true)) { render(view: "create", model: [myInstance: myInstance]) return } flash.message = message(code: 'default.created.message', args: [message(code: 'my.label', default: 'Allgemein'), myInstance.id]) redirect(action: "page1", id: myInstance.id) } When I redirect to page1, then all my textfield data are gone from the textfields, but they are in the Database. Can you help me please. Regards |
|
This post has NOT been accepted by the mailing list yet.
|
|
This post was updated on .
Hy MIchael,
thank you for your help, but when I try something of the exercises, an error appears. Do I have to add something in a folder when I add this <g:javascript library="jquery" /> in the head tag? Because I always get this error: HTTP Status 405 - -------------------------------------------------------------------------------- type Status report message description The specified HTTP method is not allowed for the requested resource (). -------------------------------------------------------------------------------- Apache Tomcat/7.0.25 |
|
This post has NOT been accepted by the mailing list yet.
Yes, add
<g:javascript library="jquery"/> inside the head section and add grails.views.javascript.library="jquery" in Config.groovy, if not allready defined. |
|
Hi MLoe,
I did it, but the same error appears. Unfortunately the Grails website is down and I cannot read the instructions. :/ Regards |
|
Hi again.
OK, jquery is running now, but I didn't get it. I don't know how to write the code. I have a button in the view which should save the textfields and checkboxes into the DB: <g:remoteLink class="button" action="ajaxsave" value="${message(code: 'my.button.save', default: 'Save')}" /> Is that correct for jquery? and then I have this function: - when i run it, there is nothing in the DB so i have to call a save function and not an update. - my identifier (primariy key is the ID the problem is, when i have nothing saved before, i have no ID: def ajaxsave() { def myInstance = new My(params) render(view: "create", id:myInstance.id) } Well this does not work. Is there a good tutorial or can someone help me? The only thing what the button should do is to save the values in the textfields into the DB and nothing more. No page reloading, no forwarding to another page, nothing. |
|
This post has NOT been accepted by the mailing list yet.
The controller action should not render the complete view
render(view: "create", id:myInstance.id) but only a part of your view using a template see http://grails.org/doc/latest/ref/Controllers/render.html |
|
Hm, when I try this:
def ajaxsave() { def myInstance = new My(params) render( template: "form", id: myInstance.id) // or render( template: "form", id: myInstance.id) } It doesn't work either. The main problem is, that the data in the form (textfields and checkboxes) is not in the fields any more. Is there any other solution? |
|
This post has NOT been accepted by the mailing list yet.
g:remoteLink is GET request to fetch the data, to submit your data you should use formRemote or submitToRemote
There are several way to submit your data using ajax and jquery. jQuery.ajax({ url: $(form).attr('action'), data: $(form).serialize(), type:'POST', success: function(data) { // Do your success actions } });
On Wed, Jun 6, 2012 at 6:34 PM, DrunkeN [via Grails] <[hidden email]> wrote: Hm, when I try this:
Cheers,
Lok
|
|
Hi Lok,
sorry but I am totally new to jQuery and Ajax. Where is this code located? In the head tag? When i put this into my gsp file: jQuery.ajax({ url: $(form).attr('ajaxsave'), data: $(form).serialize(), type:'POST', success: function(data) { // Do your success actions ?? - my success action should be to load the textField data into the DB, I hope I am not wrong. } }); |
| Powered by Nabble | Edit this page |
