Results 1 to 2 of 2

Thread: Trying to load a form with data

  1. #1

    Default Trying to load a form with data

    Hi all, I'm new to Ext and am going through the book Learning Ext JS.

    I've created a formPanel, and I'm trying load two fields on the form.

    I created a servlet that returns the following:
    Code:
    {"data":[{"id":"1"},{"title":"Example Movie Title"},{"description":"Example description"}],"success":true}
    This data is coming back fine in the load url response, but neither the title or description is loaded into the form.

    Here's my formPanel and my load call:

    Code:
                Ext.QuickTips.init();
                var movie_form = new Ext.FormPanel({
                        url: 'http://localhost:8080/ExtExamples/MovieSubmitServlet',
                        renderTo: document.body,
                        id: 'movie_form',
                        frame: true,
                        title: 'Movie Information Form',
                        width: 250,
                        items: [{
                                    xtype: 'textfield',
                                    fieldLabel: 'Title',
                                    name: 'title',
                                    id: 'title',
                                    allowBlank: false,
                                    listeners: {
                                        specialkey: function(f,e){
                                            if (e.getKey() == e.ENTER) {
                                                movie_form.getForm().submit();
                                            }
                                        }                    
                                    }                                
                                },{
                                    xtype: 'textfield',
                                    fieldLabel: 'Director',
                                    name: 'director',
                                    vtype: 'name'                                
                                },{
                                    xtype: 'datefield',
                                    fieldLabel: 'Released',
                                    name: 'released',
                                    disabledDays: [1,2,3,4,5]
                                },{                              
                                    xtype: 'radio',
                                    fieldLabel: 'Filmed In',
                                    name: 'filmed_in',
                                    boxLabel: 'Color'
                                },{
                                    xtype: 'radio',
                                    hideLabel: false,
                                    labelSeparator: '',
                                    name: 'filmed_in',
                                    boxLabel: 'Black & White'
                                },{
                                    xtype: 'checkbox',
                                    fieldLabel: 'Bad Movie',
                                    name: 'bad_movie'    
                                },{
                                    xtype: 'combo',
                                    name: 'genre',
                                    fieldLabel: 'Genre',
                                    mode: 'local',
                                    store: genres,
                                    displayField:'genre',
                                    width: 130,
                                    triggerAction : 'all',
                                    listeners: {
                                        select: function(f,r,i){
                                            if (i == 0){
                                                Ext.Msg.prompt('New Genre','Name',Ext.emptyFn);
                                            }
                                        }
                                    }
                                },{                                
                                    xtype: 'htmleditor',
                                    name: 'description',
                                    id: 'description',
                                    hideLabel: true,
                                    labelSeparator: '',
                                    height: 100,
                                    anchor: '100%'
                                },{
                                    buttons: [{
                                        text: 'Save',
                                        handler: function(){
                                            movie_form.getForm().submit({
                                                success: function(f,a){
                                                    Ext.Msg.alert('Success', 'It worked');
                                                },
                                                failure: function(f,a){
                                                    if (a.failureType === Ext.form.Action.CONNECT_FAILURE)
                                                        {Ext.Msg.alert('Failure', 'Server reported:' + a.response.status + a.response.statusText);
                                                    }
                                                    if (a.failureType === Ext.form.Action.SERVER_INVALID){
                                                        Ext.Msg.alert('Warning', a.result.errormsg);
                                                    }
                                                }
                                            });
                                        }
                                        },{
                                        text: 'Reset',
                                        handler: function(){
                                        movie_form.getForm().reset();
                                        }
                                    }]                                                                                                                
                        }]
                });               
                    
                movie_form.getForm().load({url:'LoadMovieFormServlet',params:{id: 1},
                    success: function (f, a) {
                    console.debug("SUCCESS");
                    },
                    failure: function (f, a) {
                    console.debug("FAILURE");
                    }
                });
    Any idea as to why title and description is not getting loaded?

    Thanks in advance.

  2. #2

    Default

    I figured it out, my response was not formatted correct, it had an array in it which is not what the action expects. Here's the correct format:

    Code:
    {"data":{"title":"Example Movie Title","description":"Example description"},"success":true}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •