0

Get file from XHtml input tag

asked 2009-07-08 06:32:48 +0800

timshiu gravatar image timshiu
51

updated 2009-07-08 06:34:11 +0800

I would like to ask if we can get the file binary from XHtml input tag in zscript????
e.g.
<zk>
<window title="File Upload" border="normal" xmlns:h="http://www.w3.org/1999/xhtml">
<h:input id="fileUpload" type="file" />
<button label="Test">
<attribute name="onClick">
// Get the file binary from fileUpload control
// ....
</attribute>
</button>
</window>
</zk>

I know that we can use FileUpload control instead. But I got an error when Upload button in FileUpload control is clicked.
Error message:
org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener(Lorg/apache/commons/fileupload/ProgressListener;)V

My situation is quite complicated. The zul page is put inside a iframe which is belongs to a porlet in a Portal page. The FileUpload control is worked fine in the zul page alone but not inside the iframe of the porlet.

So I would like to find a workaround for file uploading.
I'm using ZK 3.6.2.
Thanks.

delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2009-07-08 10:48:58 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

what is the exception stack trace?

link publish delete flag offensive edit

answered 2009-07-09 01:55:42 +0800

timshiu gravatar image timshiu
51

updated 2009-07-09 01:58:22 +0800

Only the following text is shown after I browsed the file and clicked the Upload button.
org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener(Lorg/apache/commons/fileupload/ProgressListener;)V

This text is shown before the Cancel button and after the text [Specify a file located in your local system]. (And the Upload button is disappeared)

I tried to try .... catch .... if any exception is thrown and nothing is caught.
Also, nothing is logged in the Portal page log.

Are there any other way to log the exception stack????

link publish delete flag offensive edit

answered 2009-07-09 02:35:22 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

updated 2009-07-09 02:35:54 +0800

I don't think you can use this kind of way to get a file upload form a HTML input with type "file"
ZK didn't do any thing in this case, it's PURE HTML way, I guess.
and
in onClick, you tried to get the binary data , I didn't see how you get it, did you call fileUpload.getWhat()??

link publish delete flag offensive edit

answered 2009-07-09 02:58:00 +0800

timshiu gravatar image timshiu
51

updated 2009-07-09 02:58:32 +0800

Let me summarize my questions again.
What I want to do is to get the file binary from client side.

1) I tried use FileUpload control in ZK, but the FileUpload control throw error when Upload button is clicked.
Error message:
org.apache.commons.fileupload.servlet.ServletFileUpload.setProgressListener(Lorg/apache/commons/fileupload/ProgressListener;)V
The error message is just shown at the UI and I cannot find any exception stack. (The error only thrown in my Portal page but just fine in normal webpage)

2) Then, I want to find if any workaround existed to get the file binary. (This is my first question)
I tried to write the sample code:
<zk>
<window title="File Upload" border="normal" xmlns:h="http://www.w3.org/1999/xhtml">
<h:input id="fileUpload" type="file" />
<button label="Test">
<attribute name="onClick">
// Get the file binary from fileUpload control
// ....
</attribute>
</button>
</window>
</zk>

But I don't know if ZK is able to get the file binary from the pure xhtml control. (i.e. I don't know what function should be called in the onClick function of the Test button)

So, my questions are:
1) Does anyone know what's wrong with the FileUpload control for my case???? What can I do to get the exception stack.
2) Is there any workaround for file upload???? e.g. get the file binary directly from xhtml

Thanks a lot.

link publish delete flag offensive edit

answered 2009-07-09 03:36:07 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

then I guess you are using a version of apache commons which is too old to run with zk.
you could update this jar to newer, or use the jar in zk-bin release directly.

link publish delete flag offensive edit

answered 2009-07-09 03:37:47 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

jar name is commons-fileupload.jar

link publish delete flag offensive edit

answered 2009-07-09 03:46:26 +0800

timshiu gravatar image timshiu
51

updated 2009-07-09 03:53:07 +0800

Thanks for your prompt response.

I have tried changing the commons-fileupload.jar, even download the latest version (1.2.1) from the official site and the error still occurred.

And may I ask you a question about Java. Is there any method we can trace the class that is loaded from which jar file or class file? I suspected this issue may be due to another old jar file containing the classes inside commons-fileupload.jar....

link publish delete flag offensive edit

answered 2009-07-09 07:07:04 +0800

timshiu gravatar image timshiu
51

To Dennis,

Thanks for your kindly help on this issue. I finally located an older version of common-fileupload.jar in the system and the FileUpload control work fine in my Portal page now.
Thank you very much.

link publish delete flag offensive edit

answered 2011-09-22 18:48:04 +0800

aktejo gravatar image aktejo
155 3

HI, have similiar problem problem with file upload , I was using button with upload =true , everything is fine in our local network, but it raises render exception when we are using vpn

I thing we are trying to find pure html solution. Any body knows how?

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-07-08 06:32:48 +0800

Seen: 625 times

Last updated: Sep 22 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More