我正在使用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