I am trying this simple ExtJS - Grails/Groovy test. My Groovy Server Page ( gsp ) file contains the below ExtJS code:
- It has two fields State Code and State Name.
- User enters the details and click on Submit.
- The Submit triggers the handler which further POSTs the form to Controller class.
function createTender() {
var submitHandler = function() {
alert("Submit Pressed !");
var formPanel = Ext.getCmp('stateForm');
formPanel.getForm().submit({
url : 'state/saveState',
method : 'POST',
success : function() {
alert('State saved successfully!');
},
failure : function() {
alert('State save failed!');
}
});
}
Ext.create('Ext.form.Panel',{
id: 'stateForm',
height: 300,
width: 400,
bodyPadding: 10,
title: 'Create State',
items: [{
xtype:'textfield',
fieldLabel: 'State Code',
name: 'stateCode',
allowBlank:false
}, {
xtype:'textfield',
fieldLabel: 'State Name',
name: 'stateName'
}],
buttons: [{
text: 'Save',
handler: submitHandler
},{
text: 'Cancel'
}],
renderTo: Ext.getBody()
});
}
Below is the StateController class with the action/method saveState. It just prints the state code and does nothing.
class StateController {
static scaffold = true
def saveState = {
println "Into saveTender() method !!!"
println params.stateCode
// Steps to save the state code and name into Database.
}
}
Problem:
- The saveState method is printing both the println statements. However, like you can see, I am not returning anything, because I don't know what should I return to the gsp. My intention is just to save the state details and throw an alert saying 'State saved Successfully!' message.
- But, the Ext code in gsp is throwing the "State save Failed!" message.
I want to return success from Controller to gsp. How do I do it? Please don't mind if this question is too naive as I am a beginner.