我正在使用GWT 2.4。我試圖提交一個AJAX請求,唯一的輸入是頁面上文本字段的值。這裏是我如何將處理程序附加到頁面的按鈕...GWT:無法從文本框中獲取價值
public void onModuleLoad() {
...
final com.google.gwt.dom.client.Element submitElement = Document.get().getElementById(SUBMIT_BUTTON_ID);
final Button submitButton = Button.wrap(submitElement);
...
// Add a handler to send the name to the server
GetHtmlHandler handler = new GetHtmlHandler();
submitButton.addClickHandler(handler);
}
但是,這是問題所在。在我的處理程序中,每當我嘗試獲取文本字段的值時,它總是返回頁面第一次加載時輸入到文本字段中的值,而不是最新的值...
class GetHtmlHandler implements ClickHandler {
/**
* Fired when the user clicks on the submitButton.
*/
public void onClick(ClickEvent event) {
submitRequest();
}
/**
* Send the name from the nameField to the server and wait for a
* response.
*/
private void submitRequest() {
...
final Element nameFieldElement = DOM.getElementById(Productplus_gwt.NAME_FIELD_ID);
// This always returns an old value.
String docId = nameFieldElement.getAttribute("value");
任何人都知道我可以在我的處理程序中寫入GWT代碼,以返回給定其頁面ID的文本字段的最新值?
謝謝 - 戴夫
謝謝你。 DOM.getElementProperty確實解決了這個問題。 – Dave
在GWT2.6中不推薦使用此方法是否有可用於獲取DOM元素值的新方法。 – Jess