You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Paolo Di Tommaso <pa...@gmail.com> on 2006/10/05 09:23:06 UTC

AjaxFormSubmitBehavior to upload a file

I'm trying to upload a file using AjaxFormSubmitBehavior using code like the
following :

fileUploadField = new FileUploadField("fileUpload");
fileUploadField.add( new AjaxFormSubmitBehavior(form,"onchange") {

    protected void onSubmit(AjaxRequestTarget arg0) {
        FileUpload file = fileUploadField.getFileUpload();
        System.out.println( ">>> " +  file.getClientFileName() );
    }

} );
form.add( fileUploadField );


But I get the following exception:


05-Oct-2006 09:10:48 [11] E - ServletRequest does not contain multipart
content
java.lang.IllegalStateException: ServletRequest does not contain multipart
content
    at wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(
MultipartServletWebRequest.java:85)
    at wicket.protocol.http.servlet.ServletWebRequest.newMultipartWebRequest
(ServletWebRequest.java:226)
    at wicket.markup.html.form.Form.handleMultiPart(Form.java:1070)
    at wicket.markup.html.form.Form.onFormSubmitted(Form.java:285)
    at wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(
AjaxFormSubmitBehavior.java:89)
    at wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:167)
...

I would like to postpone full form validation and submit having the ability
to upload a document using ajax (like gmail attachments for example). Is ti
possible in some way?

Thank you,

- Paolo

Re: AjaxFormSubmitBehavior to upload a file

Posted by Paolo Di Tommaso <pa...@gmail.com>.
Ok, it is clear.

But I think it won't be difficult to find a workaround.

I will let you know.

Thanks,

- Paolo


On 10/5/06, Matej Knopp <ma...@knopp.sk> wrote:
>
> That won't work. There's no way to upload a file using XmlHttpRequest
> (ajax). The only way to upload file and not to reload whole page is to
> use a hidden iframe as a form target, but there's no direct support in
> wicket for that.
>
> -Matej
>
> Paolo Di Tommaso wrote:
> > I'm trying to upload a file using AjaxFormSubmitBehavior using code like
> > the
> > following :
> >
> > fileUploadField = new FileUploadField("fileUpload");
> > fileUploadField.add( new AjaxFormSubmitBehavior(form,"onchange") {
> >
> >    protected void onSubmit(AjaxRequestTarget arg0) {
> >        FileUpload file = fileUploadField.getFileUpload();
> >        System.out.println( ">>> " +  file.getClientFileName() );
> >    }
> >
> > } );
> > form.add( fileUploadField );
> >
> >
> > But I get the following exception:
> >
> >
> > 05-Oct-2006 09:10:48 [11] E - ServletRequest does not contain multipart
> > content
> > java.lang.IllegalStateException: ServletRequest does not contain
> multipart
> > content
> >    at wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(
> > MultipartServletWebRequest.java:85)
> >    at
> wicket.protocol.http.servlet.ServletWebRequest.newMultipartWebRequest
> > (ServletWebRequest.java:226)
> >    at wicket.markup.html.form.Form.handleMultiPart(Form.java:1070)
> >    at wicket.markup.html.form.Form.onFormSubmitted(Form.java:285)
> >    at wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(
> > AjaxFormSubmitBehavior.java:89)
> >    at wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:167)
> > ...
> >
> > I would like to postpone full form validation and submit having the
> ability
> > to upload a document using ajax (like gmail attachments for example). Is
> ti
> > possible in some way?
> >
> > Thank you,
> >
> > - Paolo
> >
>
>

Re: AjaxFormSubmitBehavior to upload a file

Posted by Matej Knopp <ma...@knopp.sk>.
That won't work. There's no way to upload a file using XmlHttpRequest 
(ajax). The only way to upload file and not to reload whole page is to 
use a hidden iframe as a form target, but there's no direct support in 
wicket for that.

-Matej

Paolo Di Tommaso wrote:
> I'm trying to upload a file using AjaxFormSubmitBehavior using code like 
> the
> following :
> 
> fileUploadField = new FileUploadField("fileUpload");
> fileUploadField.add( new AjaxFormSubmitBehavior(form,"onchange") {
> 
>    protected void onSubmit(AjaxRequestTarget arg0) {
>        FileUpload file = fileUploadField.getFileUpload();
>        System.out.println( ">>> " +  file.getClientFileName() );
>    }
> 
> } );
> form.add( fileUploadField );
> 
> 
> But I get the following exception:
> 
> 
> 05-Oct-2006 09:10:48 [11] E - ServletRequest does not contain multipart
> content
> java.lang.IllegalStateException: ServletRequest does not contain multipart
> content
>    at wicket.protocol.http.servlet.MultipartServletWebRequest.<init>(
> MultipartServletWebRequest.java:85)
>    at wicket.protocol.http.servlet.ServletWebRequest.newMultipartWebRequest
> (ServletWebRequest.java:226)
>    at wicket.markup.html.form.Form.handleMultiPart(Form.java:1070)
>    at wicket.markup.html.form.Form.onFormSubmitted(Form.java:285)
>    at wicket.ajax.form.AjaxFormSubmitBehavior.onEvent(
> AjaxFormSubmitBehavior.java:89)
>    at wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:167)
> ...
> 
> I would like to postpone full form validation and submit having the ability
> to upload a document using ajax (like gmail attachments for example). Is ti
> possible in some way?
> 
> Thank you,
> 
> - Paolo
>