2012-09-23 57 views
1

當我執行下面的代碼,我可以看到我的鉻異常記錄,如:Ext.form.Panel有沒有方法「getEl」

Uncaught TypeError: Object [object Object] has no method '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(); 
     } 
    }] 

我已經在網絡中定義該servlet包含名稱,類和網址的.xml文件。

請讓我知道如何解決此問題。

Regards,

回答

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 
      }); 
     } 
    }] 
+0

感謝您的迴應。我試過你發佈的第一個例子,並得到這個:'所請求的資源(/ Demo/jsp/FormServlet)不可用.'該servlet存在於src文件夾下,包名稱com.controller。但是看看這個錯誤,看起來像是在web內容下的jsp文件夾下搜索的servlet是不正確的。我嘗試了一些替換url的選項,例如:url:/Demo/scr/com.controller.FormServlet,但它沒有奏效。請幫助我傳遞給網址的值。 – user182944

+0

@ user182944查看文件夾結構,您可能需要先導航回來。你可以使用'..'進行存檔,而不是像'../scr/com.controller.FormSrtvlet – sra

+0

這樣的文件夾名,當我檢查FormServlet.java的屬性時,我得到了路徑。在url中,我用這個匹配了相同的URL:'../ src/com/controller/FormServlet',但它仍然沒有工作......不知道到底是什麼URL: – user182944