Hm, it seems like i can get the behaviour I expect by overiding the inner
form button's onSubmit method and setting setDefaultFormProcessing(false)
on it as in this code.
public class Test extends WebPage {
public Test() {
MandatoryProductsForm outer = new
MandatoryProductsForm("outerForm");
NewPhoneForm inner = new NewPhoneForm("innerForm");
Button innerButton = new Button("innerButton") {
public void onSubmit() {
((NewPhoneForm)getForm()).onSubmit();
}
};
innerButton.setDefaultFormProcessing(false);
inner.add(innerButton);
outer.add(new Button("outerButton"));
outer.add(inner);
add(outer);
}
class MandatoryProductsForm extends Form {
MandatoryProductsForm(String s) {
super(s);
}
protected void onSubmit() {
System.err.println("Submit outer form");
}
}
class NewPhoneForm extends Form {
NewPhoneForm(String s) {
super(s);
}
protected void onSubmit() {
System.err.println("Submit inner form");
}
}
}
and this html
<html>
<body>
TEST
<form wicket:id="outerForm">
<form wicket:id="innerForm">
<input type="submit" wicket:id="innerButton" value="INNER"
/>
</form>
<input type="submit" wicket:id="outerButton" value="OUTER" />
</form>
</body>
</html>
Is this the way it's supposed to be done ?. My understanding was that this
should happen automatically, and i suppose i will have to do my own
validation on the inner form now (haven't tested that part).
/Steen
2008/1/23, James Carman <[EMAIL PROTECTED]>:
>
> Okay, I stand corrected. We had this question come up on the Tapestry
> users group and I don't believe Tapestry supports it (at least it
> didn't). I guess I just assumed Wicket didn't either. There's
> another reason for me to make the switch! :) I'm going to have to go
> look into this. Sounds like an interesting feature and I want to see
> how they do it.
>
> On 1/23/08, Steen Larsen <[EMAIL PROTECTED]> wrote:
> > According to the javadoc for Form it is possible because the inner form
> gets
> > substituted with span tags. It says:
> >
> > <quote>
> > Forms can be nested. You can put a form in another form. Since HTML
> doesn't
> > allow nested <form> tags, the inner forms will be rendered using the
> <div>
> > tag. You have to submit the inner forms using explicit components (like
> > Button or SubmitLink), you can't rely on implicit submit behavior (by
> using
> > just <input type="submit"> that is not attached to a component).
> > </quote>
> >
> > It is mentioned in other threads, I just don't know what I do wrong.
> >
> > /Steen
> >
> > 2008/1/23, James Carman <[EMAIL PROTECTED]>:
> > >
> > > http://www.thescripts.com/forum/thread95602.html
> > >
> > >
> > > On 1/23/08, Steen Larsen <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hi,
> > > >
> > > > I have seen that nested forms should be possible in Wicket 1.3, so i
> > > have
> > > > tried to use it in one of my projects, but for some reason when
> > > submitting
> > > > the inner form, only the outer form submit method is run. The code
> looks
> > > > something like this:
> > > >
> > > > In a WebPage class
> > > >
> > > > MandatoryProductsForm form = new
> > > > MandatoryProductsForm("mandatoryProductsForm");
> > > > add(form);
> > > > Order order = getOrder();
> > > > form.setModel(new CompoundPropertyModel(order));
> > > > NewPhoneForm pForm = new NewPhoneForm("phoneForm");
> > > > pForm.add(new Button("searchPhone"));
> > > > form.add(pForm);
> > > >
> > > > where the forms are
> > > >
> > > > class MandatoryProductsForm extends Form {
> > > > MandatoryProductsForm(String s) {
> > > > super(s);
> > > > }
> > > >
> > > > protected void onSubmit() {
> > > > Order order = (Order) getModelObject();
> > > > System.err.println("pn = " + order.getNewPhoneNumber());
> > > > setOrder(order);
> > > > setResponsePage(AdditionalProducts.class);
> > > > }
> > > > }
> > > >
> > > > class NewPhoneForm extends Form {
> > > > NewPhoneForm(String s) {
> > > > super(s);
> > > > }
> > > >
> > > > protected void onSubmit() {
> > > > System.err.println("Submit inner form");
> > > > }
> > > > }
> > > >
> > > > and the html is
> > > >
> > > > <form wicket:id="mandatoryProductsForm">
> > > > <form wicket:id="phoneForm">
> > > > <input type="submit" wicket:id="searchPhone"
> > > > value="Søg"/>
> > > > </form>
> > > > <input type="submit" name="continue" value="Videre">
> > > > </form>
> > > >
> > > > when pressing the searchPhone button I would expect the
> NewPhoneForm's
> > > > onSubmit method to be run but that doesn't happen. Anyone know why ?
> > > >
> > > > /Steen
> > > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>