Take the 2-minute tour ×

I'm using GWT 2.4. I'm trying to submit an AJAX request with the only input being the value of a text field on the page. Here is how I attach the handler to the page's button ...

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();

But here's the problem. In my handler, whenever I try and get the value of the text field, it always returns the value entered in the text field when the page was first loaded, as opposed to what the most current value is ...

class GetHtmlHandler implements ClickHandler {
     * Fired when the user clicks on the submitButton.
    public void onClick(ClickEvent event) {

     * 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");

Anyone know how I can write GWT code inside my handler to return the most current value of a text field given its page id?

Thanks, - Dave

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

Try using DOM.getPropertyString / DOM.getElementProperty

Following is the javadoc from GWT source for getAttribute function. It clearly says that the support for javascript's "getAttribute" function could be inconsistent for a few browsers and thus Element and subclasses should be used.

Alternatively you can use DOM.getPropertyString to fetch a value which uses object notation of javascript to get te current value

* Retrieves an attribute value by name.  Attribute support can be
* inconsistent across various browsers.  Consider using the accessors in
* {@link Element} and its specific subclasses to retrieve attributes and
* properties.
* @param name The name of the attribute to retrieve
* @return The Attr value as a string, or the empty string if that attribute
*         does not have a specified or default value
public final String getAttribute(String name) {
    return DOMImpl.impl.getAttribute(this, name);

I tried using javascript's "getAttribute" function to get value of a text field in IE8 and FF6. IE gave the updated value of the text field while FF did not. Here is the fiddle


share|improve this answer
Thanks for that. DOM.getElementProperty indeed solved the problem. –  Dave Oct 31 '11 at 13:21
add comment

Well like you said it's an AJAX request so whatever code you have on ... the GWT code will continue to run.

You should use the callback of the request and check the value of the nameFieldElement at that moment.

share|improve this answer
add comment

Your Answer


