UploadItem Question

Folks,

I was able to get a file uploaded using UploadItem . No problems.

However, I would like to restrict the type of files (for instance just *.xls and *.csv) . How can we achieve this?
Do I have to parse the filename extension? Or is there a smarter way to do this?

Thanks

You cannot have the browser dialog restrict the file types displayed. Add a validator that checks the extension of the file name.

Validator question

I was trying to get a validator working for the filetype. I need to validate and do additional work immediately when focus moves from the UploadItem field.

ChangedEvent doesnt trigger.

I’m using the BlurEvent by using the addBlurEventHandler.

However, the form has not saved the data yet…So, getValues on the form has nothing in it.

How can I extract the filename to be uploaded from the form field?

Any clues?

Try this.

uploadItem.getDisplayValue()

This will give u the filename!!!

Cheers,
Hetal

getDisplayValue()

Thanks.

getDisplayValue did not work either.

I think since UploadItem is an HTML form control, I cant get its data immediately (without submitting).

Any other suggestions? Surely someone has faced this :slight_smile:

There is a small suggestion here… it may be silly but its a behaviour I am facing.. may not be the same for u..

In Mozilla the uploadItem doesnt work properly for me… However m using the button click handler and u r using something else.
On click of button Upload, I perform a check for null filename and if no file is selected I send out a prompt saying fileName should not be empty… But on click of browse if the file is selected i.e I can see its full path on the UI.. then the onclick of Upload button should upload but it still gives the prompt saying filename is empty.. which is the wrong behavior…

But the same testcase works fine in Chrome.. Can you try testing your code in Chrome.. M saying this coz I am doing the same thing as u are.. validator for extensions and this was my approach.. I fail to understand how you are not able to get the display value if a file is selected..

Thanks,
Hetal

more

yes. I see the same behavior . On Chrome it works.

http://www.smartclient.com/docs/6.5.1/a/b/c/go.html#group..upload

The link above talks about possible validation errors. That is probably what you are facing.

In my case, I can see the selected file after the “Browse” press. I just cant get access to it before submitting the form.

I am going to change my design a little bit, so that I will just have the uploaditem on this form. My servlet will do the rest of the work. That is more dependable.

Can the SmartGWT team figure out why this is causing a problem??

I have a standalone test case here.. the server side code isnt important.. U can add whatever u like on press of submit() to connect to the server… but the client code is as simple as this..

Test: ON Mozilla

  1. Do not select file.. click on Upload.. Prompt shown..
  2. Select File.. Click on upload.. Prompt still shown (Which shudnt be the case)

Test: ON Chrome

  1. Do not select file.. click on Upload.. Prompt shown..
  2. Select File.. Click on upload.. Call made to the server (Desired behavior)

I would highly appreciate a reply on this.. I really have to get this bug fixed.. Server side validation is needed to be avoided wherever client side validation is poss. Hence cant change design..

Thanks,
Hetal

UploadWidget.java (2.12 KB)

Try FileItem

hetal,

Try using ‘FileItem’ instead of ‘UploadItem’.

It helped go past the validation errors.

I would call it magic.. but I checked out the latest build.. 5th May.. and it works fine in Firefox with UploadItem. Aint very sure if anything has been changed but it works!!

I couldnt replace with FileItem coz my server side code broke with that.

Hope urs works too!

Cheers,
Hetal