2010-07-28 57 views
0

我是GWT的新手,並且遇到了在我的對話框中顯示AJAX調用結果的問題。GWT/JAVA - 在對話框中獲取AJAX調用

設置我的對話框,Vpanel和響應標籤瀏覽:

VerticalPanel eventDetailWindow = new VerticalPanel(); 

    final DialogBox dialogBox2 = new DialogBox(); 
    dialogBox2.setText("Event Detail"); 
    dialogBox2.setAnimationEnabled(true); 

    final HTML serverResponse3 = new HTML("<b> ok, this is working</b>"); 
    serverResponse3.addStyleName("detailView"); 

    eventDetailWindow.add(serverResponse3); 
    eventDetailWindow.addStyleName("detailWindow"); 
    dialogBox2.setWidget(eventDetailWindow); 
    RootPanel.get("detailWindow").add(eventDetailWindow); 

然後,在的onSuccess方法我有這樣的:

dialogBox2.setText("Remote Procedure Call"); 
serverResponse3.setHTML(result); 
dialogBox2.center(); 
closeButton.setFocus(true); 

然而,當火災,響應顯示在頁面上,而不是在對話框中,對話框是空的。它看起來像它的設置一樣的起動器項目 - 這工作正常..

有人可以幫我... ...?

回答

2

不要使用RootPanel.get("detailWindow").add(eventDetailWindow); 如果你想只添加到dialogBox2

使用這樣的:

dialogBox2.setWidget(eventDetailWindow); 

和你不必添加dialogBox2.show();因爲dialogBox2.center();代碼最初將顯示dialogBox2。

package com.ex.client; 

import com.google.gwt.core.client.EntryPoint; 
import com.google.gwt.event.dom.client.ClickEvent; 
import com.google.gwt.event.dom.client.ClickHandler; 
import com.google.gwt.user.client.ui.Button; 
import com.google.gwt.user.client.ui.DialogBox; 
import com.google.gwt.user.client.ui.HTML; 
import com.google.gwt.user.client.ui.RootPanel; 
import com.google.gwt.user.client.ui.VerticalPanel; 


public class Example implements EntryPoint { 

public void onModuleLoad() { 
     VerticalPanel eventDetailWindow = new VerticalPanel(); 

     final DialogBox dialogBox2 = new DialogBox(); 
     dialogBox2.setText("Event Detail"); 
     dialogBox2.setAnimationEnabled(true); 

     final HTML serverResponse3 = new HTML("<b> ok, this is working</b>"); 
     serverResponse3.addStyleName("detailView"); 

     eventDetailWindow.add(serverResponse3); 
     eventDetailWindow.addStyleName("detailWindow"); 
     dialogBox2.setWidget(eventDetailWindow); 
     Button b= new Button("click"); 
     b.addClickHandler(new ClickHandler() { 

     @Override 
     public void onClick(ClickEvent event) { 
      dialogBox2.setText("Remote Procedure Call"); 
      serverResponse3.setHTML("result"); 
      dialogBox2.center(); 
     } 
    }); 

     RootPanel.get().add(b); 

    } 
} 
0

您正在將eventDetailWindow添加到頁面上的某些內容上,並且在DialogBox上看不到.show()的調用。你能發佈你的完整代碼嗎?