You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Tito <nj...@gmail.com> on 2011/12/19 13:12:41 UTC

Add items and then submit a form

Hi, I'm creating a page with a form.
The form asks for personal information and also for information to add some
items.

For example

General information
Name: _______
Lastname: _______

Item information
Item number: _______
Item description: ______

Add item (button)

Item number | Description
1                 |  something
2                 |  a thing

Save (button)

I tryed with nested forms but when I click on "Add item" validations on
Name and LastName stop the submit. I thought on an ajax solution but i
don't know how to do it.

I mean, I need validations of general information and validations of item
information. Could you give an idea of how to do something like this?
I think it could be a standard problem.

Thanks in advance.

Tito

Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
Well, I solved the problem.
Just submitting the form that adds items by ajax in order to avoid the
reload of the entire page and keep fields of the other form.

Thanks!

Tito

On Tue, Jan 31, 2012 at 9:07 AM, Tito <nj...@gmail.com> wrote:

> Hi, I'm working again on this. And I realized that I have a problem with
> this method.
>
> The problem is when I submit the form that adds items, the main form
> does't keep its state. I mean if I a complete something like 'name' then
> click 'add item' the name desapear because it is not submitted.
>
> Do you understand my problem?
>
> But if I nest forms it works but the problem are validations on main form
> when inner form is submitted.
>
> Thanks in advance
>
> Tito
>
> On Tue, Dec 20, 2011 at 8:38 AM, Tito <nj...@gmail.com> wrote:
>
>> Great!!
>> It works ok!
>>
>> Thank you very much.
>>
>> On Tue, Dec 20, 2011 at 6:21 AM, Andrea Del Bene <ad...@ciseonweb.it>wrote:
>>
>>> This should not be a big deal. Wicket lets you put form submitting
>>> button outside form itself. All you have to do to make it work is to pass
>>> the form to component's constructor.
>>>
>>>
>>> HTML code:
>>>
>>>
>>> <form wicket:id="form1">
>>>
>>> </form>
>>>
>>> <form wicket:id="form2">
>>> <input  type="submit" value="form2" wicket:id="submit2"/>
>>>
>>> </form>
>>>
>>> <input type="submit" value="form1"  wicket:id="submit1"/>
>>>
>>>
>>> Java code:
>>>
>>>
>>>
>>> add(form1 = new Form("form1"){
>>>           @Override
>>>        protected void onSubmit() {
>>>            super.onSubmit();
>>>            System.out.println("form1");
>>>        }
>>>       });
>>>
>>>    add(new SubmitLink("submit1", form1));
>>>
>>>    Form form2;
>>>
>>>    add(form2 =new Form("form2"){
>>>            @Override
>>>            protected void onSubmit() {
>>>                super.onSubmit();
>>>                System.out.println("form2");
>>>            }
>>>       });
>>>
>>>    form2.add(new SubmitLink("submit2"));
>>>
>>>
>>>
>>> Button "submit1" is outside its form and you have two separated form.
>>>
>>>
>>>
>>>  I think you are right.
>>>> Using an AjaxButton it works a litle more like I want.
>>>>
>>>> Nevertheless I still have a problem, because outer form submits inner
>>>> form.
>>>>
>>>> In my case I think that I need two separated forms, but the problem is
>>>> how
>>>> to put add button y save button in the correct place. I mean, the
>>>> layout is
>>>> what you mentioned but the behavior is more like two separated forms.
>>>> Thank you!
>>>>
>>>> On Mon, Dec 19, 2011 at 2:04 PM, Andrea Del Bene<ad...@ciseonweb.it>
>>>> **wrote:
>>>>
>>>
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>

Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
Hi, I'm working again on this. And I realized that I have a problem with
this method.

The problem is when I submit the form that adds items, the main form does't
keep its state. I mean if I a complete something like 'name' then click
'add item' the name desapear because it is not submitted.

Do you understand my problem?

But if I nest forms it works but the problem are validations on main form
when inner form is submitted.

Thanks in advance

Tito

On Tue, Dec 20, 2011 at 8:38 AM, Tito <nj...@gmail.com> wrote:

> Great!!
> It works ok!
>
> Thank you very much.
>
> On Tue, Dec 20, 2011 at 6:21 AM, Andrea Del Bene <ad...@ciseonweb.it>wrote:
>
>> This should not be a big deal. Wicket lets you put form submitting button
>> outside form itself. All you have to do to make it work is to pass the form
>> to component's constructor.
>>
>>
>> HTML code:
>>
>>
>> <form wicket:id="form1">
>>
>> </form>
>>
>> <form wicket:id="form2">
>> <input  type="submit" value="form2" wicket:id="submit2"/>
>>
>> </form>
>>
>> <input type="submit" value="form1"  wicket:id="submit1"/>
>>
>>
>> Java code:
>>
>>
>>
>> add(form1 = new Form("form1"){
>>           @Override
>>        protected void onSubmit() {
>>            super.onSubmit();
>>            System.out.println("form1");
>>        }
>>       });
>>
>>    add(new SubmitLink("submit1", form1));
>>
>>    Form form2;
>>
>>    add(form2 =new Form("form2"){
>>            @Override
>>            protected void onSubmit() {
>>                super.onSubmit();
>>                System.out.println("form2");
>>            }
>>       });
>>
>>    form2.add(new SubmitLink("submit2"));
>>
>>
>>
>> Button "submit1" is outside its form and you have two separated form.
>>
>>
>>
>>  I think you are right.
>>> Using an AjaxButton it works a litle more like I want.
>>>
>>> Nevertheless I still have a problem, because outer form submits inner
>>> form.
>>>
>>> In my case I think that I need two separated forms, but the problem is
>>> how
>>> to put add button y save button in the correct place. I mean, the layout
>>> is
>>> what you mentioned but the behavior is more like two separated forms.
>>> Thank you!
>>>
>>> On Mon, Dec 19, 2011 at 2:04 PM, Andrea Del Bene<ad...@ciseonweb.it>*
>>> *wrote:
>>>
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
Great!!
It works ok!

Thank you very much.

On Tue, Dec 20, 2011 at 6:21 AM, Andrea Del Bene <ad...@ciseonweb.it>wrote:

> This should not be a big deal. Wicket lets you put form submitting button
> outside form itself. All you have to do to make it work is to pass the form
> to component's constructor.
>
>
> HTML code:
>
>
> <form wicket:id="form1">
>
> </form>
>
> <form wicket:id="form2">
> <input  type="submit" value="form2" wicket:id="submit2"/>
>
> </form>
>
> <input type="submit" value="form1"  wicket:id="submit1"/>
>
>
> Java code:
>
>
>
> add(form1 = new Form("form1"){
>           @Override
>        protected void onSubmit() {
>            super.onSubmit();
>            System.out.println("form1");
>        }
>       });
>
>    add(new SubmitLink("submit1", form1));
>
>    Form form2;
>
>    add(form2 =new Form("form2"){
>            @Override
>            protected void onSubmit() {
>                super.onSubmit();
>                System.out.println("form2");
>            }
>       });
>
>    form2.add(new SubmitLink("submit2"));
>
>
>
> Button "submit1" is outside its form and you have two separated form.
>
>
>
>  I think you are right.
>> Using an AjaxButton it works a litle more like I want.
>>
>> Nevertheless I still have a problem, because outer form submits inner
>> form.
>>
>> In my case I think that I need two separated forms, but the problem is how
>> to put add button y save button in the correct place. I mean, the layout
>> is
>> what you mentioned but the behavior is more like two separated forms.
>> Thank you!
>>
>> On Mon, Dec 19, 2011 at 2:04 PM, Andrea Del Bene<ad...@ciseonweb.it>**
>> wrote:
>>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Add items and then submit a form

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
This should not be a big deal. Wicket lets you put form submitting 
button outside form itself. All you have to do to make it work is to 
pass the form to component's constructor.

HTML code:


<form wicket:id="form1">

</form>
<form wicket:id="form2">
<input  type="submit" value="form2" wicket:id="submit2"/>

</form>

<input type="submit" value="form1"  wicket:id="submit1"/>


Java code:


add(form1 = new Form("form1"){
            @Override
         protected void onSubmit() {
             super.onSubmit();
             System.out.println("form1");
         }
        });

     add(new SubmitLink("submit1", form1));

     Form form2;
     add(form2 =new Form("form2"){
             @Override
             protected void onSubmit() {
                 super.onSubmit();
                 System.out.println("form2");
             }
        });

     form2.add(new SubmitLink("submit2"));



Button "submit1" is outside its form and you have two separated form.


> I think you are right.
> Using an AjaxButton it works a litle more like I want.
>
> Nevertheless I still have a problem, because outer form submits inner form.
>
> In my case I think that I need two separated forms, but the problem is how
> to put add button y save button in the correct place. I mean, the layout is
> what you mentioned but the behavior is more like two separated forms.
> Thank you!
>
> On Mon, Dec 19, 2011 at 2:04 PM, Andrea Del Bene<ad...@ciseonweb.it>wrote:


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
I think you are right.
Using an AjaxButton it works a litle more like I want.

Nevertheless I still have a problem, because outer form submits inner form.

In my case I think that I need two separated forms, but the problem is how
to put add button y save button in the correct place. I mean, the layout is
what you mentioned but the behavior is more like two separated forms.

Thank you!

On Mon, Dec 19, 2011 at 2:04 PM, Andrea Del Bene <ad...@ciseonweb.it>wrote:

> I think this happens because you submit your forms with a simple HTML
> "submit" button, not mapped to a Wicket component.  Try to explicitly add a
> submit component to the forms. I've added SubmitLink to both forms and
> forms are submitted as expected.
>
> HTML code:
>
> <form wicket:id="form1">
> <form wicket:id="form2">
> <input  type="submit" value="form2" wicket:id="submit2"/>
>
> </form>
>
> <input type="submit" value="form1 (outer)"  wicket:id="submit1"/>
> </form>
>
>
> Java code:
>
>  Form form1;
>    add(form1 = new Form("form1"){
>           @Override
>        protected void onSubmit() {
>            super.onSubmit();
>            System.out.println("form1");
>        }
>       });
>
>    form1.add(new SubmitLink("submit1"));
>
>        Form form2;
>        form1.add(form2 =new Form("form2"){
>           @Override
>        protected void onSubmit() {
>            super.onSubmit();
>            System.out.println("form2");
>        }
>       });
>
>    form2.add(new SubmitLink("submit2"));
>
>
>  Here I have something like a QuickStart.
>> In this reduced example I can verify this behavior. I checked that link
>> but
>> it seems to work different.
>>
>> In this case both submit button do the same. I'm using wicket 1.4.19.
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Add items and then submit a form

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
I think this happens because you submit your forms with a simple HTML 
"submit" button, not mapped to a Wicket component.  Try to explicitly 
add a submit component to the forms. I've added SubmitLink to both forms 
and forms are submitted as expected.

HTML code:

<form wicket:id="form1">
<form wicket:id="form2">
<input  type="submit" value="form2" wicket:id="submit2"/>

</form>

<input type="submit" value="form1 (outer)"  wicket:id="submit1"/>
</form>


Java code:

   Form form1;
     add(form1 = new Form("form1"){
            @Override
         protected void onSubmit() {
             super.onSubmit();
             System.out.println("form1");
         }
        });

     form1.add(new SubmitLink("submit1"));

         Form form2;
         form1.add(form2 =new Form("form2"){
            @Override
         protected void onSubmit() {
             super.onSubmit();
             System.out.println("form2");
         }
        });

     form2.add(new SubmitLink("submit2"));

> Here I have something like a QuickStart.
> In this reduced example I can verify this behavior. I checked that link but
> it seems to work different.
>
> In this case both submit button do the same. I'm using wicket 1.4.19.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
Here I have something like a QuickStart.
In this reduced example I can verify this behavior. I checked that link but
it seems to work different.

In this case both submit button do the same. I'm using wicket 1.4.19.


package com.keepcon.web.administration.users;

import java.util.ArrayList;
import java.util.Collection;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;


public class NestedForms extends WebPage {

@SuppressWarnings("unused")
private String name;
 private final Collection<String> values = new ArrayList<String>();

public NestedForms() {
 Form<Void> outerForm = new Form<Void>("outerForm");
PropertyModel<String> nameModel = new PropertyModel<String>(this, "name");
 outerForm.add(new RequiredTextField<String>("name", nameModel));

final IModel<String> valueModel = new Model<String>("");

Form<Void> innerForm = new Form<Void>("innerForm") {
@Override
 protected void onSubmit() {
values.add(valueModel.getObject());
valueModel.setObject("");
 }
};

innerForm.add(new RequiredTextField<String>("value", valueModel));

outerForm.add(innerForm);

outerForm.add(new Label("values", new AbstractReadOnlyModel<String>() {

@Override
public String getObject() {
return NestedForms.this.values.toString();
 }
}));
outerForm.add(new Label("nameSubmitted", nameModel));

add(outerForm);
add(new FeedbackPanel("feedback"));
 }
}



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd
">
<head></head>
<body>
<div wicket:id="feedback"></div>
<form wicket:id="outerForm">
 <table>
<tr>
<td>Name:</td>
 <td><input type="text" wicket:id="name" /></td>
</tr>
 </table>
<form wicket:id="innerForm">
<table>
 <tr>
<td>Value:</td>
<td><input type="text" wicket:id="value" /></td>
 </tr>
<tr>
<td><input type="submit" value="Add" /></td>
 <td></td>
</tr>
</table>
 </form>
<table>
<tr>
 <td><input type="submit" value="Save" /></td>
<td></td>
 </tr>
<tr>
<td>Datos subidos:</td>
 <td></td>
</tr>
<tr>
 <td>Name:</td>
<td><span wicket:id="nameSubmitted"></span></td>
 </tr>
<tr>
<td>Values:</td>
 <td><span wicket:id="values"></span></td>
</tr>
 </table>
</form>
</body>
</html>



On Mon, Dec 19, 2011 at 11:10 AM, Andrea Del Bene <ad...@ciseonweb.it>wrote:

> This is strange end should not happened: https://cwiki.apache.org/**
> WICKET/nested-forms.html<https://cwiki.apache.org/WICKET/nested-forms.html>.
> Maybe the problem is on code side. Can you show the initialization code for
> the two forms?
>
>  Yes, I have this layout. Is the first I tested.
>>
>> The problem with this is that when I click Add Item buttom information is
>> not submitted because general validations stops it. I mean, if I don't
>> complete name field i can't add items.
>>
>> It seems like inner form submit is submitting outer form.
>>
>> Thanks!
>>
>> On Mon, Dec 19, 2011 at 10:16 AM, Andrea Del Bene<ad...@ciseonweb.it>*
>> *wrote:
>>
>>  Hi,
>>>
>>> nested form should work fine. I mean something like this:
>>>
>>> _________________________
>>> |<main form>
>>> | Name:..
>>> | Lastname:...
>>> |
>>> | ________________________
>>> | |<item (inner) form>
>>> | | item number:...
>>> | | item number:...
>>> | |<Add item button>
>>> | |______________________
>>> |
>>> |<save button>
>>> |_______________________
>>>
>>> Do you have this forms layout? 'Add item button' must be added to 'item
>>> form' and only to this form.
>>>
>>>  Hi, I'm creating a page with a form.
>>>
>>>> The form asks for personal information and also for information to add
>>>> some
>>>> items.
>>>>
>>>> For example
>>>>
>>>> General information
>>>> Name: _______
>>>> Lastname: _______
>>>>
>>>> Item information
>>>> Item number: _______
>>>> Item description: ______
>>>>
>>>> Add item (button)
>>>>
>>>> Item number | Description
>>>> 1                 |  something
>>>> 2                 |  a thing
>>>>
>>>> Save (button)
>>>>
>>>> I tryed with nested forms but when I click on "Add item" validations on
>>>> Name and LastName stop the submit. I thought on an ajax solution but i
>>>> don't know how to do it.
>>>>
>>>> I mean, I need validations of general information and validations of
>>>> item
>>>> information. Could you give an idea of how to do something like this?
>>>> I think it could be a standard problem.
>>>>
>>>> Thanks in advance.
>>>>
>>>> Tito
>>>>
>>>>
>>>>  ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apa**che.org<http://apache.org>
>>> <us...@wicket.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Add items and then submit a form

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
This is strange end should not happened: 
https://cwiki.apache.org/WICKET/nested-forms.html. Maybe the problem is 
on code side. Can you show the initialization code for the two forms?

> Yes, I have this layout. Is the first I tested.
>
> The problem with this is that when I click Add Item buttom information is
> not submitted because general validations stops it. I mean, if I don't
> complete name field i can't add items.
>
> It seems like inner form submit is submitting outer form.
>
> Thanks!
>
> On Mon, Dec 19, 2011 at 10:16 AM, Andrea Del Bene<ad...@ciseonweb.it>wrote:
>
>> Hi,
>>
>> nested form should work fine. I mean something like this:
>>
>> _________________________
>> |<main form>
>> | Name:..
>> | Lastname:...
>> |
>> | ________________________
>> | |<item (inner) form>
>> | | item number:...
>> | | item number:...
>> | |<Add item button>
>> | |______________________
>> |
>> |<save button>
>> |_______________________
>>
>> Do you have this forms layout? 'Add item button' must be added to 'item
>> form' and only to this form.
>>
>>   Hi, I'm creating a page with a form.
>>> The form asks for personal information and also for information to add
>>> some
>>> items.
>>>
>>> For example
>>>
>>> General information
>>> Name: _______
>>> Lastname: _______
>>>
>>> Item information
>>> Item number: _______
>>> Item description: ______
>>>
>>> Add item (button)
>>>
>>> Item number | Description
>>> 1                 |  something
>>> 2                 |  a thing
>>>
>>> Save (button)
>>>
>>> I tryed with nested forms but when I click on "Add item" validations on
>>> Name and LastName stop the submit. I thought on an ajax solution but i
>>> don't know how to do it.
>>>
>>> I mean, I need validations of general information and validations of item
>>> information. Could you give an idea of how to do something like this?
>>> I think it could be a standard problem.
>>>
>>> Thanks in advance.
>>>
>>> Tito
>>>
>>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Add items and then submit a form

Posted by Tito <nj...@gmail.com>.
Yes, I have this layout. Is the first I tested.

The problem with this is that when I click Add Item buttom information is
not submitted because general validations stops it. I mean, if I don't
complete name field i can't add items.

It seems like inner form submit is submitting outer form.

Thanks!

On Mon, Dec 19, 2011 at 10:16 AM, Andrea Del Bene <ad...@ciseonweb.it>wrote:

> Hi,
>
> nested form should work fine. I mean something like this:
>
> _________________________
> | <main form>
> | Name:..
> | Lastname:...
> |
> | ________________________
> | | <item (inner) form>
> | | item number:...
> | | item number:...
> | | <Add item button>
> | |______________________
> |
> | <save button>
> |_______________________
>
> Do you have this forms layout? 'Add item button' must be added to 'item
> form' and only to this form.
>
>  Hi, I'm creating a page with a form.
>> The form asks for personal information and also for information to add
>> some
>> items.
>>
>> For example
>>
>> General information
>> Name: _______
>> Lastname: _______
>>
>> Item information
>> Item number: _______
>> Item description: ______
>>
>> Add item (button)
>>
>> Item number | Description
>> 1                 |  something
>> 2                 |  a thing
>>
>> Save (button)
>>
>> I tryed with nested forms but when I click on "Add item" validations on
>> Name and LastName stop the submit. I thought on an ajax solution but i
>> don't know how to do it.
>>
>> I mean, I need validations of general information and validations of item
>> information. Could you give an idea of how to do something like this?
>> I think it could be a standard problem.
>>
>> Thanks in advance.
>>
>> Tito
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@wicket.**apache.org<us...@wicket.apache.org>
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Add items and then submit a form

Posted by Andrea Del Bene <ad...@ciseonweb.it>.
Hi,

nested form should work fine. I mean something like this:

_________________________
| <main form>
| Name:..
| Lastname:...
|
| ________________________
| | <item (inner) form>
| | item number:...
| | item number:...
| | <Add item button>
| |______________________
|
| <save button>
|_______________________

Do you have this forms layout? 'Add item button' must be added to 'item 
form' and only to this form.
> Hi, I'm creating a page with a form.
> The form asks for personal information and also for information to add some
> items.
>
> For example
>
> General information
> Name: _______
> Lastname: _______
>
> Item information
> Item number: _______
> Item description: ______
>
> Add item (button)
>
> Item number | Description
> 1                 |  something
> 2                 |  a thing
>
> Save (button)
>
> I tryed with nested forms but when I click on "Add item" validations on
> Name and LastName stop the submit. I thought on an ajax solution but i
> don't know how to do it.
>
> I mean, I need validations of general information and validations of item
> information. Could you give an idea of how to do something like this?
> I think it could be a standard problem.
>
> Thanks in advance.
>
> Tito
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org