Re: Form from post to multipart

2016-09-10 Thread Martin Grigorov
Hi,

Thanks for sharing your solution!
IMO this is a special case that is not that common to be in Wicket core.
It also assumes that Form#setOutputMarkupId(true) has been called.

What about marking the form as multipart from the beginning
(Form.setMultipart(true)) ? I think it should work even i there are no
FileUploadField fields in it.

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

On Mon, Sep 5, 2016 at 11:54 PM, Илья Нарыжный  wrote:

> Hello!
>
> Issue has been solved by the following code. What do you think about
> inclusion of it into official wicket code?
>
> /**
>  * Update Form EncType to "multipart/form-data" of there is something which
> require multipart is in target ajax response
>  */
> public class FixFormEncTypeListener extends
> AjaxRequestTarget.AbstractListener {
>
> @Override
> public void onAfterRespond(Map map, IJavaScriptResponse
> response) {
> Set
formsToUpdate = new HashSet<>(); > for (Map.Entry entry : map.entrySet()) { > Component component = entry.getValue(); > Form form = component.findParent(Form.class); > if(form!=null && form.isMultiPart()) formsToUpdate.add(form. > getRootForm()); > } > for (Form form : formsToUpdate) { > response.addJavaScript("{var e = > document.getElementById('"+form.getMarkupId()+"'); e.encoding= > 'multipart/form-data'; e.encType=e.encoding;}"); > } > } > } > > Thanks, > > Ilya > > - > Orienteer(http://orienteer.org) - open source Business Application > Platform > > > On Mon, Sep 5, 2016 at 2:32 AM, Илья Нарыжный wrote: > > > It will not solve the problem... Component which want to be mutatable > > doesn't want to know about parent forms. So forms in ajax mode should > > somehow adjust encoding automatically, but resending of whole content of > a > > form is not good option, imho. > > > > Thanks, > > > > Ilya > > > > - > > Orienteer(http://orienteer.org) - open source Business Application > > Platform > > > > > > On Mon, Sep 5, 2016 at 1:29 AM, Maxim Solodovnik > > wrote: > > > >> Maybe you can use nested forms? > >> > >> On Mon, Sep 5, 2016 at 2:51 PM, Илья Нарыжный wrote: > >> > >> > Hello! > >> > > >> > Please help to figure out is there some good solution for the > following > >> > situation: > >> > > >> > There is a page with Form with in it. Form contains lots of components > >> > underneath. And some components can be changed by AJAX from "view" > >> > representation to "edit". And sometimes "edit" is some file upload > >> > component. And in this case to work proporly: form encoding should be > >> > changed to multipart. But I don't want to make it by sending in ajax > >> > response whole Form, because it's pretty big... Is there a good way > >> update > >> > just a component and if parent form is not multipart - switch it to > >> > multipart? > >> > > >> > Thanks, > >> > > >> > Ilya > >> > > >> > - > >> > Orienteer(http://orienteer.org) - open source Business Application > >> > Platform > >> > > >> > >> > >> > >> -- > >> WBR > >> Maxim aka solomax > >> > > > > >

Re: Form from post to multipart

2016-09-05 Thread Илья Нарыжный
Hello!

Issue has been solved by the following code. What do you think about
inclusion of it into official wicket code?

/**
 * Update Form EncType to "multipart/form-data" of there is something which
require multipart is in target ajax response
 */
public class FixFormEncTypeListener extends
AjaxRequestTarget.AbstractListener {

@Override
public void onAfterRespond(Map map, IJavaScriptResponse
response) {
Set formsToUpdate = new HashSet<>();
for (Map.Entry entry : map.entrySet()) {
Component component = entry.getValue();
Form form = component.findParent(Form.class);
if(form!=null && form.isMultiPart()) formsToUpdate.add(form.getRootForm());
}
for (Form form : formsToUpdate) {
response.addJavaScript("{var e =
document.getElementById('"+form.getMarkupId()+"'); e.encoding=
'multipart/form-data'; e.encType=e.encoding;}");
}
}
}

Thanks,

Ilya

-
Orienteer(http://orienteer.org) - open source Business Application Platform


On Mon, Sep 5, 2016 at 2:32 AM, Илья Нарыжный  wrote:

> It will not solve the problem... Component which want to be mutatable
> doesn't want to know about parent forms. So forms in ajax mode should
> somehow adjust encoding automatically, but resending of whole content of a
> form is not good option, imho.
>
> Thanks,
>
> Ilya
>
> -
> Orienteer(http://orienteer.org) - open source Business Application
> Platform
>
>
> On Mon, Sep 5, 2016 at 1:29 AM, Maxim Solodovnik 
> wrote:
>
>> Maybe you can use nested forms?
>>
>> On Mon, Sep 5, 2016 at 2:51 PM, Илья Нарыжный  wrote:
>>
>> > Hello!
>> >
>> > Please help to figure out is there some good solution for the following
>> > situation:
>> >
>> > There is a page with Form with in it. Form contains lots of components
>> > underneath. And some components can be changed by AJAX from "view"
>> > representation to "edit". And sometimes "edit" is some file upload
>> > component. And in this case to work proporly: form encoding should be
>> > changed to multipart. But I don't want to make it by sending in ajax
>> > response whole Form, because it's pretty big...  Is there a good way
>> update
>> > just a component and if parent form is not multipart - switch it to
>> > multipart?
>> >
>> > Thanks,
>> >
>> > Ilya
>> >
>> > -
>> > Orienteer(http://orienteer.org) - open source Business Application
>> > Platform
>> >
>>
>>
>>
>> --
>> WBR
>> Maxim aka solomax
>>
>
>


Re: Form from post to multipart

2016-09-05 Thread Илья Нарыжный
It will not solve the problem... Component which want to be mutatable
doesn't want to know about parent forms. So forms in ajax mode should
somehow adjust encoding automatically, but resending of whole content of a
form is not good option, imho.

Thanks,

Ilya

-
Orienteer(http://orienteer.org) - open source Business Application Platform


On Mon, Sep 5, 2016 at 1:29 AM, Maxim Solodovnik 
wrote:

> Maybe you can use nested forms?
>
> On Mon, Sep 5, 2016 at 2:51 PM, Илья Нарыжный  wrote:
>
> > Hello!
> >
> > Please help to figure out is there some good solution for the following
> > situation:
> >
> > There is a page with Form with in it. Form contains lots of components
> > underneath. And some components can be changed by AJAX from "view"
> > representation to "edit". And sometimes "edit" is some file upload
> > component. And in this case to work proporly: form encoding should be
> > changed to multipart. But I don't want to make it by sending in ajax
> > response whole Form, because it's pretty big...  Is there a good way
> update
> > just a component and if parent form is not multipart - switch it to
> > multipart?
> >
> > Thanks,
> >
> > Ilya
> >
> > -
> > Orienteer(http://orienteer.org) - open source Business Application
> > Platform
> >
>
>
>
> --
> WBR
> Maxim aka solomax
>


Re: Form from post to multipart

2016-09-05 Thread Maxim Solodovnik
Maybe you can use nested forms?

On Mon, Sep 5, 2016 at 2:51 PM, Илья Нарыжный  wrote:

> Hello!
>
> Please help to figure out is there some good solution for the following
> situation:
>
> There is a page with Form with in it. Form contains lots of components
> underneath. And some components can be changed by AJAX from "view"
> representation to "edit". And sometimes "edit" is some file upload
> component. And in this case to work proporly: form encoding should be
> changed to multipart. But I don't want to make it by sending in ajax
> response whole Form, because it's pretty big...  Is there a good way update
> just a component and if parent form is not multipart - switch it to
> multipart?
>
> Thanks,
>
> Ilya
>
> -
> Orienteer(http://orienteer.org) - open source Business Application
> Platform
>



-- 
WBR
Maxim aka solomax


Form from post to multipart

2016-09-05 Thread Илья Нарыжный
Hello!

Please help to figure out is there some good solution for the following
situation:

There is a page with Form with in it. Form contains lots of components
underneath. And some components can be changed by AJAX from "view"
representation to "edit". And sometimes "edit" is some file upload
component. And in this case to work proporly: form encoding should be
changed to multipart. But I don't want to make it by sending in ajax
response whole Form, because it's pretty big...  Is there a good way update
just a component and if parent form is not multipart - switch it to
multipart?

Thanks,

Ilya

-
Orienteer(http://orienteer.org) - open source Business Application Platform