Search code examples
javagwtfile-uploadgxt

Analyse logic of GXT FileUploadField


GXT 3.x only.

Could someone analyse and explain the connection between the three private fields in FileUploadField?

Specifically,

  1. where is the onclick action of the button that would trigger fileinput display? If not where, then how.
  2. How does the fileinput.getValue() get transferred to the text input widget?

If you could answer the above questions, you should be able to answer this one ... (but please don't answer this question if you do not provide answers to the above two questions). Is the following statement true, somewhat true or incidental?

  • GXT has deliberately made it impossible to trigger button onclick programmatically because Security Concerns should not allow the file input element to be triggered programmatically.
  • If that is true, (why?) I could still access the button and fileinput elements programmatically, anyway. There's no stopping me or anyone.

EDIT
OK, never mind item 2: fileinput value is transferred to text input at onChange method.


Solution

    1. There is none. There is a <input type=file> painted invisibly over top of the 'real' button. When you click on this, the dialog comes up - the click 'hit's the <input type=file> instead of the button, but onBrowserEvent tells the button to behave like it was clicked anyway. As far as I'm aware, this is the only way to gain access to the file system (i.e. the "Choose a file") provided by the browser (at least that supports browsers without the new file api, or flash or another plugin).

    2. The <input type=file> exposes access to the name (which may or may not be complete or even real) to the javascript on the page. This is, as you note, available in a DOM change event from the input itself. Only the file name is available (again, without the file api), and it might have a fake path (i.e. IE) or no path (everyone else).

    3. This is not a security concern that GXT has anything to do with - instead the rube-goldberg layout of the dom of the field is to deal with the browser's security limitations. Using private on the <input> is just making it clear that you shouldn't be access it directly, and does nothing meaningful to prevent you from reading it. If you subclass this, go after getFileInput(), otherwise, use JSNI and the so-called violator pattern to grab a reference to the file field or that method.

    4. Yep - this isn't about security, this is about writing maintainable code. See also https://stackoverflow.com/a/2954949/860630.