You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by cojy <co...@hotmail.fr> on 2014/09/28 10:25:46 UTC
AjaxSubmitLink not working when fileUpload in Form
Hi,
When I am having a fileUpload in a form, the wicket ajax debug throw the
following error:
"An error occurred while executing Ajax request:TypeError: object is not a
function"
and my ajaxsubmitlink actions onSubmit() or onError() are not called (so
nothing happens).
I am not sure if I am doing something wrong, if this is expected or if this
is a bug.
Here is a simple code that I used:
TestPage.java:
public final class TestPage extends PersistancePanel {
public TestPage(String id, Eventmgr em) {
super(id);
Form form = new TestPage.TestPageForm("eventCreationForm", em);
form.setMultiPart(true); // Enable multipart mode (need for uploads
file)
form.setMaxSize(Bytes.kilobytes(128));
form.setModel(new CompoundPropertyModel(em));
add(form);
}
public final class TestPageForm extends Form<Eventmgr> {
public TestPageForm(final String id, Eventmgr eventMgr) {
super(id);
add(new FileUploadField("fileUpload"));
final WebMarkupContainer wmc2 = new WebMarkupContainer("wmc");
wmc2.setOutputMarkupId(true);
RefreshingView rv = new RefreshingView<Event>("subEventForm") {
@Override
//protected void populateItem(ListItem item) {
protected void populateItem(Item<Event> item) {
final Event event = (Event) item.getModelObject();
item.add(new TextArea<>("descr2", new
PropertyModel<String>(event, "descr")));
}
@Override
protected Iterator<IModel<Event>> getItemModels() {
return eventMgr.getILevents().iterator();
}
};
rv.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
wmc2.add(rv);
add(wmc2);
AjaxSubmitLink addSubevent = new AjaxSubmitLink("addSubevent",
this) {
@Override
public void onSubmit(AjaxRequestTarget target, Form form) {
eventMgr.getEvents().add(new Event());
System.out.println("OK");
target.add(wmc2);
}
};
addSubevent.setDefaultFormProcessing(false);
add(addSubevent);
}
@Override
protected void onSubmit() {
System.out.println("submit done");
}
}
}
TestPage.html
<html xmlns:wicket>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>CreateEvent</title>
</head>
<body>
<wicket:panel>
<form wicket:id="eventCreationForm">
<strong><wicket:message key="event.addposter"/>:
</strong> <input wicket:id="fileUpload" type="file"/>
<div wicket:id="wmc">
<wicket:message key="event.description"/>:
<textarea name="description2" wicket:id="descr2" rows="2"
cols="40"></textarea>
</div>
+ <#> <wicket:message key="event.subevent.add"/> <br/>
<input type="submit" name="submit"/>
</form>
</wicket:panel>
</body>
</html>
Thank you for your help,
Cojy.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxSubmitLink-not-working-when-fileUpload-in-Form-tp4667740.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: AjaxSubmitLink not working when fileUpload in Form
Posted by cojy <co...@hotmail.fr>.
Hello,
Thank you for your feedback.
So I took the example and started adding my code and it works !
After multiple comparisons and some tests I found out that the problem is in
the HTML and arises when the <input type="submit" name="submit"/> is inside
the <form> </form> tags.
So no issue whatsoever having the submit in the form, unless there is a
fileUpload. That's still a bit weird.
But anyway, problem solved, so thanks again !
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AjaxSubmitLink-not-working-when-fileUpload-in-Form-tp4667740p4667766.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: AjaxSubmitLink not working when fileUpload in Form
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
The demo example at
http://www.wicket-library.com/wicket-examples-6.0.x/ajax/upload seems to
work fine.
Take a look at its code (wicket-examples module) and see what is different
with your code.
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Sun, Sep 28, 2014 at 10:25 AM, cojy <co...@hotmail.fr> wrote:
> Hi,
> When I am having a fileUpload in a form, the wicket ajax debug throw the
> following error:
>
> "An error occurred while executing Ajax request:TypeError: object is not a
> function"
>
> and my ajaxsubmitlink actions onSubmit() or onError() are not called (so
> nothing happens).
> I am not sure if I am doing something wrong, if this is expected or if this
> is a bug.
>
> Here is a simple code that I used:
>
> TestPage.java:
> public final class TestPage extends PersistancePanel {
> public TestPage(String id, Eventmgr em) {
> super(id);
>
> Form form = new TestPage.TestPageForm("eventCreationForm", em);
> form.setMultiPart(true); // Enable multipart mode (need for uploads
> file)
> form.setMaxSize(Bytes.kilobytes(128));
> form.setModel(new CompoundPropertyModel(em));
> add(form);
>
> }
>
> public final class TestPageForm extends Form<Eventmgr> {
> public TestPageForm(final String id, Eventmgr eventMgr) {
> super(id);
>
> add(new FileUploadField("fileUpload"));
>
> final WebMarkupContainer wmc2 = new WebMarkupContainer("wmc");
> wmc2.setOutputMarkupId(true);
>
> RefreshingView rv = new RefreshingView<Event>("subEventForm") {
> @Override
> //protected void populateItem(ListItem item) {
> protected void populateItem(Item<Event> item) {
>
>
> final Event event = (Event) item.getModelObject();
>
>
> item.add(new TextArea<>("descr2", new
> PropertyModel<String>(event, "descr")));
> }
>
> @Override
> protected Iterator<IModel<Event>> getItemModels() {
> return eventMgr.getILevents().iterator();
> }
>
> };
> rv.setItemReuseStrategy(new ReuseIfModelsEqualStrategy());
> wmc2.add(rv);
> add(wmc2);
>
> AjaxSubmitLink addSubevent = new AjaxSubmitLink("addSubevent",
> this) {
> @Override
> public void onSubmit(AjaxRequestTarget target, Form form) {
> eventMgr.getEvents().add(new Event());
> System.out.println("OK");
> target.add(wmc2);
> }
> };
> addSubevent.setDefaultFormProcessing(false);
> add(addSubevent);
> }
> @Override
> protected void onSubmit() {
> System.out.println("submit done");
> }
> }
> }
>
> TestPage.html
> <html xmlns:wicket>
> <head>
> <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8"/>
> <title>CreateEvent</title>
> </head>
> <body>
> <wicket:panel>
>
>
> <form wicket:id="eventCreationForm">
>
>
>
>
>
> <strong><wicket:message
> key="event.addposter"/>:
> </strong> <input wicket:id="fileUpload" type="file"/>
>
>
>
>
>
> <div wicket:id="wmc">
>
>
>
>
>
> <wicket:message key="event.description"/>:
> <textarea name="description2" wicket:id="descr2" rows="2"
> cols="40"></textarea>
>
>
>
> </div>
>
> + <#> <wicket:message key="event.subevent.add"/> <br/>
> <input type="submit" name="submit"/>
> </form>
> </wicket:panel>
> </body>
> </html>
>
> Thank you for your help,
> Cojy.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/AjaxSubmitLink-not-working-when-fileUpload-in-Form-tp4667740.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
>
>