1

以下のコードを実行すると、次のようにログに記録されたChromeに例外が表示されます。

Uncaught TypeError:Object[objectObject]にはメソッド'getEl'がありません

var search = new Ext.form.Panel({
    renderTo: 'pan',
    title: 'Basic Panel',
    collapsible:true,
    width: 400,
    defaults: {width: 230},
    defaultType: 'textfield',
    bodyPadding: 10,
    //layout: 'form',
    frame:true,
    items: [{
            fieldLabel: 'Username',
            name: 'username',
            id: 'username',
            allowBlank:false
        },
        {
            fieldLabel: 'Password',
            name: 'password',
           inputType:'password',
            allowBlank:false
        },

        {
            fieldLabel: 'First Name',
            name: 'firstname',
           inputType:'text',
            allowBlank:false
        }, 
        {
            fieldLabel: 'Last Name',
            name: 'lastname',
           inputType:'text',
            allowBlank:false
        },
        {
            fieldLabel: 'E-Mail Address',
            name: 'email',
           vtype:'email',

           allowBlank:false
        },

        {
            fieldLabel: 'State',
            name: 'state',
           allowBlank:false
        },
        {
            fieldLabel: 'City',
            name: 'city',
           allowBlank:false
        }, 
       {
            fieldLabel: 'Country',
            name: 'country',
           allowBlank:false
        }, 
        {
            inputType: 'hidden',
            id: 'submitbutton',
            name: 'myhiddenbutton',
            value: 'hiddenvalue'
        }

    ],
    buttons: [{
        text: 'Submit',
        handler: function() {
            search.getForm().getEl().dom.action = 'FormServlet';
            search.getForm().getEl().dom.method = 'POST';
            search.getForm().submit();
        }
    }]

名前、クラス、およびURLを含むweb.xmlファイルでサーブレットを定義しました。

この問題を解決する方法を教えてください。

よろしく、

4

1 に答える 1

1

そんなに複雑にしないでください。ExtJS が設定をオーバーライドするか、適切な構成プロパティを使用して設定しなかったため、設定をまったく使用しなかったと思います。

両方の API リンクは次のとおりです。

これらで拡張されたデモコードは次のとおりです

var search = new Ext.form.Panel({
    renderTo: 'pan',
    title: 'Basic Panel',
    collapsible:true,
    width: 400,
    defaults: {width: 230},
    defaultType: 'textfield',
    bodyPadding: 10,
    url: 'FormServlet', // you can fix a parameter like this : FormServlet?action=create
    action: 'POST',
    frame:true,
    items: [
         //....
    ],
    buttons: [{
        text: 'Submit',
        handler: function() {
            search.getForm().submit();
        }
    }]

または、より柔軟にするためにこのようにします

var search = new Ext.form.Panel({
    renderTo: 'pan',
    title: 'Basic Panel',
    collapsible:true,
    width: 400,
    defaults: {width: 230},
    defaultType: 'textfield',
    bodyPadding: 10,
    url: 'FormServlet', 
    action: 'POST',
    frame:true,
    items: [
         //....
    ],
    buttons: [{
        text: 'Submit',
        handler: function() {
            Ext.Ajax.request({
                url : 'FormServlet',
                method:'POST', 
                params : {
                    yourParam: Ext.encode(form.getValues())
                },
                scope : this,
                //method to call when the request is successful
                success : this.onLoginSuccess,
                //method to call when the request is a failure
                failure : this.onLoginFailure
            });
        }
    }]
于 2012-09-23T07:41:16.900 に答える