onchange Event with FileUpload widget

298 views
Skip to first unread message

ramzi....@gmail.com

unread,
Dec 28, 2007, 6:01:17 PM12/28/07
to Google Web Toolkit
Hi,

I apologize if there was a post on this question, I looked around but
could not find a satisfactory solution. My goal is very simple I want
to be able to do this in GWT:
<html>
<form>
<input type="file" value="Browse" onchange="alert('ALOHA!!');" />
</form>
<html>

I want to be able to react to a change in the text box holding the
file name. I am looking for a solution other than simply using HTML or
using a form handler to submit.

One problem is that FileUpload is not a SourcesChangesEvents so there
is no way for me to register a change listener with a FileUpload, so I
tried doing the following (using onBrowserEvents)

/**
* Example of on change event with file Upload.
* @author me
*/
public class FileUploadApplication implements EntryPoint
{
public void onModuleLoad()
{
final FormPanel form = new FormPanel();
final FileUpload upload = new MyFileUpload();
form.add(upload);
DOM.setEventListener(upload.getElement(), upload);
RootPanel.get().add(form);

}

private class MyFileUpload extends FileUpload
{
protected void onLoad()
{
super.onLoad();
Window.alert("on load");
}

public void onBrowserEvent(Event event)
{
Window.alert("on browse");
}
}
}

When I open my HTML page in any mode I do get the alert that on load
occurred (no brainer) but not sure why the onBrowserEvent did not get
call I am sure I am missing the concept and onBrowseEvent might not be
what is going on, I try changing the text box of my FileUpload but
with no luck,

I am a beginner at GWT so any help on this will be appreciated,

Have a nice new year.

GWT Newbie

unread,
Dec 28, 2007, 8:41:45 PM12/28/07
to Google Web Toolkit
The better solution of making a widget as an event source is to call
sinkEvents() in the constructor of MyFileUpload, rather than
DOM.setEventListener(upload.getElement(), upload). See the document on
sinkEvents for more details.

On Dec 29, 7:01 am, "ramzi.yass...@gmail.com"
Reply all
Reply to author
Forward
0 new messages