2012-04-03 106 views
0

我剛開始使用GWT。我編寫了教程here。但是,當我創建新項目並在水平面板中添加了兩個按鈕,然後在RootPanel中,它向我顯示了我在HTML文件中創建的標題。你能告訴我可能是什麼原因嗎? 這裏是Java類中,HTML和XML: 的Java類:新GWT應用程序中的按鈕

package org.elsys.salvation.client; 

import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.user.client.ui.Button; 
import com.google.gwt.user.client.ui.HorizontalPanel; 
import com.google.gwt.user.client.ui.Label; 
import com.google.gwt.user.client.ui.RootPanel; 


public class Salvation implements EntryPoint { 

    private Button newData = new Button("New"); 
    private Button existingData = new Button("Existing"); 
    private HorizontalPanel mainHorizontalPanel = new HorizontalPanel(); 
    private Label lastUpdatedLabel = new Label(); 

    public void onModuleLoad() { 
     mainHorizontalPanel.add(newData); 
     mainHorizontalPanel.add(existingData); 
     mainHorizontalPanel.add(lastUpdatedLabel); 

     RootPanel.get("Salvation").add(mainHorizontalPanel); 
    } 

} 

的HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
     <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
     <link type="text/css" rel="stylesheet" href="Salvation.css"> 
     <title>Diploma Defences Organiser</title> 
     <script type="text/javascript" language="javascript" src="stockwatcher/stockwatcher.nocache.js"></script> 
    </head> 
    <body> 

     <h1>Diploma Defences Organiser</h1> 
     <div id="Salvation"></div> 
     <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> 
     <noscript> 
      <div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif"> 
      Your web browser must have JavaScript enabled 
      in order for this application to display correctly. 
      </div> 
     </noscript> 
    </body> 
</html> 

和XML:

<?xml version="1.0" encoding="UTF-8"?> 
<module rename-to='Salvation'> 
    <!-- Inherit the core Web Toolkit stuff.      --> 
    <inherits name='com.google.gwt.user.User'/> 

    <!-- Inherit the default GWT style sheet. You can change  --> 
    <!-- the theme of your GWT application by uncommenting   --> 
    <!-- any one of the following lines.       --> 
    <inherits name='com.google.gwt.user.theme.clean.Clean'/> 
    <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> --> 
    <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --> 
    <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>  --> 

    <!-- Other module inherits          --> 

    <!-- Specify the app entry point class.       --> 
    <entry-point class='org.elsys.salvation.client.Salvation'/> 

    <!-- Specify the paths for translatable code     --> 
    <source path='client'/> 
    <source path='shared'/> 

</module> 
+0

你是怎麼開始這個項目的。你在編碼環境中使用eclipse嗎? – Stefan 2012-04-03 14:18:41

+0

是的,日食:) – malkoto1 2012-04-03 15:30:42

回答

0

檢查該行是否是否正確:

<script type="text/javascript" language="javascript" src="stockwatcher/stockwatcher.nocache.js"></script> 

我認爲你應該有這樣的:Salvation/Salvation.nocache.js作爲腳本標記的來源。

+0

我修正了它,但只是頭只顯示... – malkoto1 2012-04-03 15:17:53

+0

@ malkoto1檢查.nocache.js文件可以從該URL訪問,它應該工作,如果nocache.js文件可從該頁面。 ... – 2012-04-03 16:07:22

0

在您選擇的瀏覽器中打開開發者控制檯。您應該能夠跟蹤所做的網絡請求。確保你的* nocache.js文件被調用並且恢復正常(狀態200)。

如果這樣工作確定沒有其他的明顯跳出來對我。也許嘗試不指定要加載到的div?

RootLayoutPanel.get().add(mainHorizontalPanel); 
+0

正在調用javascript,但在控制檯中出現以下錯誤:Uncaught TypeError:「無法設置屬性'__gwt_getProperty'的未定義」,它在該行代碼之後出現: 「function B(){if(p && q ){var b = m.getElementById(O); var c = b.contentWindow; if(A()){c .__ gwt_getProperty = function(a){return F(a)}} Salvation = null; c.gwtOnLoad y,O,s,x); n && n({moduleName:O,sessionId:o,subSystem:P,evtGroup:V,millis:(new Date).getTime(),type:W})}}「 – malkoto1 2012-04-03 16:10:47

+0

這就是生成的js很難在視覺上進行調試。你是從eclipse中的tomcat服務器運行還是編譯然後部署? – 2012-04-03 17:01:42

+0

我正在使用eclipse的Developement模式並運行它 – malkoto1 2012-04-03 17:41:51