You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Tobias Soloschenko <to...@googlemail.com> on 2015/05/14 00:02:35 UTC

Change AbstractDefaultAjaxBehavior to allow multipart

Hi all,

I am currently writing an implementation for a modern file upload based 
on dropzone.js:

https://github.com/l0rdn1kk0n/wicket-bootstrap/issues/371

I am using AbstractDefaultAjaxBehavior to send the files back to the 
server. At this place I need to adjust the AbstractDefaultAjaxBehavior 
to enable it for multipart:

         @Override
         protected AjaxRequestAttributes getAttributes()
         {
             AjaxRequestAttributes attributes = super.getAttributes();
             attributes.setMultipart(true);
             return attributes;
         }

Currently getAttributes() is set to final and I have no chance to change 
the AjaxRequestAttributes anyhow - so my suggestion would be to add a 
protected method which is called within getAttributes() so that it is 
possible to change the AjaxRequestAttributes.

An example implementation in the response method of the 
AbstractDefaultAjaxBehavior would be:

                     ServletWebRequest webRequest = 
(ServletWebRequest)getRequest();
                     MultipartServletWebRequest multiPartRequest = 
webRequest.newMultipartWebRequest(
                         Bytes.bytes(5000000), "ignored");
                     multiPartRequest.parseFileParts();
                     Map<String, List<FileItem>> files = 
multiPartRequest.getFiles();
                     System.out.println(files);

I checked it already with a demo file and the log result was:

{file=[name=dropzone.js, 
StoreLocation=/var/folders/jh/dw7vk3rs1fbf5gyms4v9k85r0000gn/T/upload_9a1ae025_411f_4e82_8f04_70dc9a7e0a79_79336009.tmp, 
size=63014bytes, isFormField=false, FieldName=file]}

What do you think of adding a method to change the AjaxRequestAttributes 
for AbstractDefaultAjaxBehavior?

kind regards

Tobias

Re: Change AbstractDefaultAjaxBehavior to allow multipart

Posted by Tobias Soloschenko <to...@googlemail.com>.
Hi Martin,

oh nooo - I oversaw that method completely. :-/ It was a bit late 
yesterday - so good that I stopped working on it and asked in the dev 
mailing list. ;-)

I'm going to finish the component today I think.

kind regards

Tobias

Am 14.05.15 um 08:56 schrieb Martin Grigorov:
> Hi Tobias,
>
> I think you need to
> override org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#updateAjaxAttributes(AjaxRequestAttributes)
> ;-)
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Thu, May 14, 2015 at 1:02 AM, Tobias Soloschenko <
> tobiassoloschenko@googlemail.com> wrote:
>
>> Hi all,
>>
>> I am currently writing an implementation for a modern file upload based on
>> dropzone.js:
>>
>> https://github.com/l0rdn1kk0n/wicket-bootstrap/issues/371
>>
>> I am using AbstractDefaultAjaxBehavior to send the files back to the
>> server. At this place I need to adjust the AbstractDefaultAjaxBehavior to
>> enable it for multipart:
>>
>>          @Override
>>          protected AjaxRequestAttributes getAttributes()
>>          {
>>              AjaxRequestAttributes attributes = super.getAttributes();
>>              attributes.setMultipart(true);
>>              return attributes;
>>          }
>>
>> Currently getAttributes() is set to final and I have no chance to change
>> the AjaxRequestAttributes anyhow - so my suggestion would be to add a
>> protected method which is called within getAttributes() so that it is
>> possible to change the AjaxRequestAttributes.
>>
>> An example implementation in the response method of the
>> AbstractDefaultAjaxBehavior would be:
>>
>>                      ServletWebRequest webRequest =
>> (ServletWebRequest)getRequest();
>>                      MultipartServletWebRequest multiPartRequest =
>> webRequest.newMultipartWebRequest(
>>                          Bytes.bytes(5000000), "ignored");
>>                      multiPartRequest.parseFileParts();
>>                      Map<String, List<FileItem>> files =
>> multiPartRequest.getFiles();
>>                      System.out.println(files);
>>
>> I checked it already with a demo file and the log result was:
>>
>> {file=[name=dropzone.js,
>> StoreLocation=/var/folders/jh/dw7vk3rs1fbf5gyms4v9k85r0000gn/T/upload_9a1ae025_411f_4e82_8f04_70dc9a7e0a79_79336009.tmp,
>> size=63014bytes, isFormField=false, FieldName=file]}
>>
>> What do you think of adding a method to change the AjaxRequestAttributes
>> for AbstractDefaultAjaxBehavior?
>>
>> kind regards
>>
>> Tobias
>>


Re: Change AbstractDefaultAjaxBehavior to allow multipart

Posted by Martin Grigorov <mg...@apache.org>.
Hi Tobias,

I think you need to
override org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#updateAjaxAttributes(AjaxRequestAttributes)
;-)

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, May 14, 2015 at 1:02 AM, Tobias Soloschenko <
tobiassoloschenko@googlemail.com> wrote:

> Hi all,
>
> I am currently writing an implementation for a modern file upload based on
> dropzone.js:
>
> https://github.com/l0rdn1kk0n/wicket-bootstrap/issues/371
>
> I am using AbstractDefaultAjaxBehavior to send the files back to the
> server. At this place I need to adjust the AbstractDefaultAjaxBehavior to
> enable it for multipart:
>
>         @Override
>         protected AjaxRequestAttributes getAttributes()
>         {
>             AjaxRequestAttributes attributes = super.getAttributes();
>             attributes.setMultipart(true);
>             return attributes;
>         }
>
> Currently getAttributes() is set to final and I have no chance to change
> the AjaxRequestAttributes anyhow - so my suggestion would be to add a
> protected method which is called within getAttributes() so that it is
> possible to change the AjaxRequestAttributes.
>
> An example implementation in the response method of the
> AbstractDefaultAjaxBehavior would be:
>
>                     ServletWebRequest webRequest =
> (ServletWebRequest)getRequest();
>                     MultipartServletWebRequest multiPartRequest =
> webRequest.newMultipartWebRequest(
>                         Bytes.bytes(5000000), "ignored");
>                     multiPartRequest.parseFileParts();
>                     Map<String, List<FileItem>> files =
> multiPartRequest.getFiles();
>                     System.out.println(files);
>
> I checked it already with a demo file and the log result was:
>
> {file=[name=dropzone.js,
> StoreLocation=/var/folders/jh/dw7vk3rs1fbf5gyms4v9k85r0000gn/T/upload_9a1ae025_411f_4e82_8f04_70dc9a7e0a79_79336009.tmp,
> size=63014bytes, isFormField=false, FieldName=file]}
>
> What do you think of adding a method to change the AjaxRequestAttributes
> for AbstractDefaultAjaxBehavior?
>
> kind regards
>
> Tobias
>