You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by pureza <pu...@gmail.com> on 2012/12/04 17:51:38 UTC

Upload file and display its contents using AJAX

Hi,

I need to upload a file, parse it and display its contents inside a
textarea, all this using ajax.

At first I tried to use jquery-file-upload, and I was able to upload the
file to an IResource as explained at
http://wicketinaction.com/2012/11/uploading-files-to-wicket-iresource/.
However, I have no idea as to how to display the contents of the file inside
the textarea when the upload is finished.

Then I tried to use a plain FileUploadField component and I attached an
AjaxFormSubmitBehavior to it, but it seems that the model is always null and
I am unable to access the uploaded files.

Any help is appreciated.

Thanks!




--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Upload file and display its contents using AJAX

Posted by pureza <pu...@gmail.com>.
Thanks Martin, I had just found
https://issues.apache.org/jira/browse/WICKET-2420 before reading your reply!

I guess that clears things.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473p4654510.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Upload file and display its contents using AJAX

Posted by Martin Grigorov <mg...@apache.org>.
Wicket uses an iframe internally for Ajax file uploads.


On Wed, Dec 5, 2012 at 11:55 AM, pureza <pu...@gmail.com> wrote:

> I was able to get rid of the submit button, but I don't understand why it
> works (maybe some wicket magic?).
>
> I have a Form object and in the onSubmit() method I read the uploaded file
> and store it in a model. I also added an AjaxFormSubmitBehavior to the form
> that updates the textarea with the contents of the file via ajax.
>
> The markup is simply:
>
>
> This works fine (i.e. when I choose a file to upload the textarea is
> updated
> with the file's contents), but I don't understand why. The form submission
> does not refresh the whole page, but I was told that the only way I could
> do
> this was using an iframe, which I'm not doing. Please note that I am also
> not using any kind of upload library such as jquery-file-upload.
>
> Do you have any idea as to why this works the way it does? I'm clueless...
>
> Thanks!
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473p4654508.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com <http://jweekend.com/>

Re: Upload file and display its contents using AJAX

Posted by pureza <pu...@gmail.com>.
I was able to get rid of the submit button, but I don't understand why it
works (maybe some wicket magic?).

I have a Form object and in the onSubmit() method I read the uploaded file
and store it in a model. I also added an AjaxFormSubmitBehavior to the form
that updates the textarea with the contents of the file via ajax.

The markup is simply:


This works fine (i.e. when I choose a file to upload the textarea is updated
with the file's contents), but I don't understand why. The form submission
does not refresh the whole page, but I was told that the only way I could do
this was using an iframe, which I'm not doing. Please note that I am also
not using any kind of upload library such as jquery-file-upload.

Do you have any idea as to why this works the way it does? I'm clueless...

Thanks!





--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473p4654508.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Upload file and display its contents using AJAX

Posted by pureza <pu...@gmail.com>.
Hi again,

I was able to get the desired result by putting an AjaxButton on the form
containing the <input type="file"> component. So, the user selects a file,
presses submit and everything works.

However, I'd prefer if the upload would start immediately after the user
selects a file. Can I get rid of the button?

Thanks.



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473p4654478.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Upload file and display its contents using AJAX

Posted by pureza <pu...@gmail.com>.
Nick,

As I said on my previous email, I can't access the file contents within an
AjaxBehavior, because FileInputField.getModelObject() is always null (maybe
I'm not setting it up correctly when I instantiate the FileInputField?).



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473p4654477.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Upload file and display its contents using AJAX

Posted by Nick Pratt <nb...@gmail.com>.
Once the file is uploaded, set the contents of the IModel backing the
TextArea, and then add the Form(or TextArea) to the AjaxRequestTarget.

On Tue, Dec 4, 2012 at 11:51 AM, pureza <pu...@gmail.com> wrote:

> Hi,
>
> I need to upload a file, parse it and display its contents inside a
> textarea, all this using ajax.
>
> At first I tried to use jquery-file-upload, and I was able to upload the
> file to an IResource as explained at
> http://wicketinaction.com/2012/11/uploading-files-to-wicket-iresource/.
> However, I have no idea as to how to display the contents of the file
> inside
> the textarea when the upload is finished.
>
> Then I tried to use a plain FileUploadField component and I attached an
> AjaxFormSubmitBehavior to it, but it seems that the model is always null
> and
> I am unable to access the uploaded files.
>
> Any help is appreciated.
>
> Thanks!
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Upload-file-and-display-its-contents-using-AJAX-tp4654473.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>