You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Tobias Knierim <to...@googlemail.com> on 2012/07/17 09:02:07 UTC

Validating form components in a refreshing view

Hi there,
I'm new to wicket and have a problem I can't find out for myself.
Maybe some of you can help me out with this.

I have a refreshingview with input fields each row. I can add new rows
on click of a button, but when I submit the form, I want to validate 2
input fields from different rows. Everything I tried so far hasn't
worked out, because I was only able to validate values from one row.

Is it even possible to do something like this?


Greetings
Tobi

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


RE: Validating form components in a refreshing view

Posted by Paul Bors <pb...@knoa.com>.
For example of how you could validate a form given multiple form fields take a look at how EqualInputValidator is implemented.

You would have to keep references to the form fields that are related and return them as an array via IFormValidator. getDependentFormComponents() of your own IFormValidator implementation. Then you can add as many of those you want to your form.

Wicket form processing:

 -------      ----------      ---------      ----------      --------      ------------ 
| Start | -> | required | -> | convert | -> | validate | -> |  push  | -> | onSubmit() |
|       |    |  checks  |    |  input  |    |  input   |    |  input |    |            |
 -------      ----------      ---------      ----------      --------      ------------ 
                  |              |                |              |                      
                 fail           fail             fail           fail       ----------- 
                  |              |                |              |        | onError() |
                   - - - - - - - - - - - - - - - - - - - - - - - - - - -> |           |
                                                                           -----------

I recommend reading "Wicket in Action" (http://manning.com/dashorst/) or any other books listed on Wicket's website (http://wicket.apache.org/learn/books/).

~ Thank you,
Paul Bors | Software Engineer | Knoa Software | 5 Union Square West, New York , NY 10003 | O: 212-807-9608 | www.knoa.com


-----Original Message-----
From: Tobias Knierim [mailto:tobias.knierim@googlemail.com] 
Sent: Tuesday, July 17, 2012 6:04 AM
To: users@wicket.apache.org
Subject: Re: Validating form components in a refreshing view

Hi Josh,

you're right,
I haven't put any in this example because I am really not sure how I should accomplish this.
If I choose a FormValidator with the FormComponents textOne and textTwo, I can just compare the values of one row.

I will extend my example later.

Tobi


2012/7/17 Josh Kamau <jo...@gmail.com>:
> Hi Tobi ;
>
> I cant see any Validation code..
>
> Josh.
>
> On Tue, Jul 17, 2012 at 12:01 PM, Tobias Knierim < 
> tobias.knierim@googlemail.com> wrote:
>
>> Hi Josh,
>>
>> I just created a little example of how my application is working:
>> I want to compare value2 from Entry1 with value1 from Entry2 and so on.
>>
>> Any ideas?
>>
>>
>> Form<Values> form = new Form<Values>("form");
>>                 add(form);
>>
>>                 RefreshingView<Entry> refreshingView = new 
>> RefreshingView<Entry>("list", values) {
>>
>>                         @Override
>>                         protected Iterator<IModel<Entry>> getItemModels() {
>>                                 List<Entry> entryList = 
>> values.getObject().getEntryList();
>>
>>                                 ModelIteratorAdapter<Entry> mia = new
>> ModelIteratorAdapter<Entry>(entryList.iterator()) {
>>
>>                                         @Override
>>                                         protected IModel<Entry> 
>> model(Entry object) {
>>                                                 return new 
>> CompoundPropertyModel<Entry>(object);
>>                                         }
>>                                 };
>>                                 return mia;
>>                         }
>>
>>                         @Override
>>                         protected void populateItem(Item<Entry> item) {
>>                                 IModel<Entry> model = 
>> item.getModel();
>>
>>                                 item.add(new 
>> TextField<String>("textOne", new PropertyModel<String>(model, 
>> "value1")));
>>                                 item.add(new 
>> TextField<String>("textTwo", new PropertyModel<String>(model, 
>> "value2")));
>>                         }
>>
>>                 };
>>
>>                 form.add(refreshingView);
>>
>> Tobi
>>
>>
>> 2012/7/17 Josh Kamau <jo...@gmail.com>:
>> > Tobi ;
>> >
>> > May be you can paste some code to show how you are constructing the 
>> > forms...
>> >
>> > I believe if you just add the validators to the components and then
>> submit
>> > the forms, it just works..
>> >
>> > Josh.
>> >
>> > On Tue, Jul 17, 2012 at 10:22 AM, Tobias Knierim < 
>> > tobias.knierim@googlemail.com> wrote:
>> >
>> >> Hi Josh,
>> >>
>> >> The whole view is wrapped in one form.
>> >>
>> >> Greetings
>> >> Tobi
>> >>
>> >> Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:
>> >>
>> >> > Hi ;
>> >> >
>> >> > Is the whole listview wrapped in 1 form or there is a form for 
>> >> > each
>> row?
>> >> >
>> >> > Josh.
>> >> >
>> >> > On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim < 
>> >> > tobias.knierim@googlemail.com> wrote:
>> >> >
>> >> >> Hi there,
>> >> >> I'm new to wicket and have a problem I can't find out for myself.
>> >> >> Maybe some of you can help me out with this.
>> >> >>
>> >> >> I have a refreshingview with input fields each row. I can add 
>> >> >> new
>> rows
>> >> >> on click of a button, but when I submit the form, I want to 
>> >> >> validate
>> 2
>> >> >> input fields from different rows. Everything I tried so far 
>> >> >> hasn't worked out, because I was only able to validate values from one row.
>> >> >>
>> >> >> Is it even possible to do something like this?
>> >> >>
>> >> >>
>> >> >> Greetings
>> >> >> Tobi
>> >> >>
>> >> >> ---------------------------------------------------------------
>> >> >> ------ To unsubscribe, e-mail: 
>> >> >> users-unsubscribe@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
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@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


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


Re: Validating form components in a refreshing view

Posted by Tobias Knierim <to...@googlemail.com>.
Hi Josh,

you're right,
I haven't put any in this example because I am really not sure how I
should accomplish this.
If I choose a FormValidator with the FormComponents textOne and
textTwo, I can just compare the values of one row.

I will extend my example later.

Tobi


2012/7/17 Josh Kamau <jo...@gmail.com>:
> Hi Tobi ;
>
> I cant see any Validation code..
>
> Josh.
>
> On Tue, Jul 17, 2012 at 12:01 PM, Tobias Knierim <
> tobias.knierim@googlemail.com> wrote:
>
>> Hi Josh,
>>
>> I just created a little example of how my application is working:
>> I want to compare value2 from Entry1 with value1 from Entry2 and so on.
>>
>> Any ideas?
>>
>>
>> Form<Values> form = new Form<Values>("form");
>>                 add(form);
>>
>>                 RefreshingView<Entry> refreshingView = new
>> RefreshingView<Entry>("list", values) {
>>
>>                         @Override
>>                         protected Iterator<IModel<Entry>> getItemModels() {
>>                                 List<Entry> entryList =
>> values.getObject().getEntryList();
>>
>>                                 ModelIteratorAdapter<Entry> mia = new
>> ModelIteratorAdapter<Entry>(entryList.iterator()) {
>>
>>                                         @Override
>>                                         protected IModel<Entry>
>> model(Entry object) {
>>                                                 return new
>> CompoundPropertyModel<Entry>(object);
>>                                         }
>>                                 };
>>                                 return mia;
>>                         }
>>
>>                         @Override
>>                         protected void populateItem(Item<Entry> item) {
>>                                 IModel<Entry> model = item.getModel();
>>
>>                                 item.add(new TextField<String>("textOne",
>> new
>> PropertyModel<String>(model, "value1")));
>>                                 item.add(new TextField<String>("textTwo",
>> new
>> PropertyModel<String>(model, "value2")));
>>                         }
>>
>>                 };
>>
>>                 form.add(refreshingView);
>>
>> Tobi
>>
>>
>> 2012/7/17 Josh Kamau <jo...@gmail.com>:
>> > Tobi ;
>> >
>> > May be you can paste some code to show how you are constructing the
>> > forms...
>> >
>> > I believe if you just add the validators to the components and then
>> submit
>> > the forms, it just works..
>> >
>> > Josh.
>> >
>> > On Tue, Jul 17, 2012 at 10:22 AM, Tobias Knierim <
>> > tobias.knierim@googlemail.com> wrote:
>> >
>> >> Hi Josh,
>> >>
>> >> The whole view is wrapped in one form.
>> >>
>> >> Greetings
>> >> Tobi
>> >>
>> >> Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:
>> >>
>> >> > Hi ;
>> >> >
>> >> > Is the whole listview wrapped in 1 form or there is a form for each
>> row?
>> >> >
>> >> > Josh.
>> >> >
>> >> > On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
>> >> > tobias.knierim@googlemail.com> wrote:
>> >> >
>> >> >> Hi there,
>> >> >> I'm new to wicket and have a problem I can't find out for myself.
>> >> >> Maybe some of you can help me out with this.
>> >> >>
>> >> >> I have a refreshingview with input fields each row. I can add new
>> rows
>> >> >> on click of a button, but when I submit the form, I want to validate
>> 2
>> >> >> input fields from different rows. Everything I tried so far hasn't
>> >> >> worked out, because I was only able to validate values from one row.
>> >> >>
>> >> >> Is it even possible to do something like this?
>> >> >>
>> >> >>
>> >> >> Greetings
>> >> >> Tobi
>> >> >>
>> >> >> ---------------------------------------------------------------------
>> >> >> To unsubscribe, e-mail: users-unsubscribe@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
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@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: Validating form components in a refreshing view

Posted by Josh Kamau <jo...@gmail.com>.
Hi Tobi ;

I cant see any Validation code..

Josh.

On Tue, Jul 17, 2012 at 12:01 PM, Tobias Knierim <
tobias.knierim@googlemail.com> wrote:

> Hi Josh,
>
> I just created a little example of how my application is working:
> I want to compare value2 from Entry1 with value1 from Entry2 and so on.
>
> Any ideas?
>
>
> Form<Values> form = new Form<Values>("form");
>                 add(form);
>
>                 RefreshingView<Entry> refreshingView = new
> RefreshingView<Entry>("list", values) {
>
>                         @Override
>                         protected Iterator<IModel<Entry>> getItemModels() {
>                                 List<Entry> entryList =
> values.getObject().getEntryList();
>
>                                 ModelIteratorAdapter<Entry> mia = new
> ModelIteratorAdapter<Entry>(entryList.iterator()) {
>
>                                         @Override
>                                         protected IModel<Entry>
> model(Entry object) {
>                                                 return new
> CompoundPropertyModel<Entry>(object);
>                                         }
>                                 };
>                                 return mia;
>                         }
>
>                         @Override
>                         protected void populateItem(Item<Entry> item) {
>                                 IModel<Entry> model = item.getModel();
>
>                                 item.add(new TextField<String>("textOne",
> new
> PropertyModel<String>(model, "value1")));
>                                 item.add(new TextField<String>("textTwo",
> new
> PropertyModel<String>(model, "value2")));
>                         }
>
>                 };
>
>                 form.add(refreshingView);
>
> Tobi
>
>
> 2012/7/17 Josh Kamau <jo...@gmail.com>:
> > Tobi ;
> >
> > May be you can paste some code to show how you are constructing the
> > forms...
> >
> > I believe if you just add the validators to the components and then
> submit
> > the forms, it just works..
> >
> > Josh.
> >
> > On Tue, Jul 17, 2012 at 10:22 AM, Tobias Knierim <
> > tobias.knierim@googlemail.com> wrote:
> >
> >> Hi Josh,
> >>
> >> The whole view is wrapped in one form.
> >>
> >> Greetings
> >> Tobi
> >>
> >> Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:
> >>
> >> > Hi ;
> >> >
> >> > Is the whole listview wrapped in 1 form or there is a form for each
> row?
> >> >
> >> > Josh.
> >> >
> >> > On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
> >> > tobias.knierim@googlemail.com> wrote:
> >> >
> >> >> Hi there,
> >> >> I'm new to wicket and have a problem I can't find out for myself.
> >> >> Maybe some of you can help me out with this.
> >> >>
> >> >> I have a refreshingview with input fields each row. I can add new
> rows
> >> >> on click of a button, but when I submit the form, I want to validate
> 2
> >> >> input fields from different rows. Everything I tried so far hasn't
> >> >> worked out, because I was only able to validate values from one row.
> >> >>
> >> >> Is it even possible to do something like this?
> >> >>
> >> >>
> >> >> Greetings
> >> >> Tobi
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: users-unsubscribe@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
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Validating form components in a refreshing view

Posted by Tobias Knierim <to...@googlemail.com>.
Hi Josh,

I just created a little example of how my application is working:
I want to compare value2 from Entry1 with value1 from Entry2 and so on.

Any ideas?


Form<Values> form = new Form<Values>("form");
		add(form);
		
		RefreshingView<Entry> refreshingView = new
RefreshingView<Entry>("list", values) {

			@Override
			protected Iterator<IModel<Entry>> getItemModels() {
				List<Entry> entryList = values.getObject().getEntryList();
				
				ModelIteratorAdapter<Entry> mia = new
ModelIteratorAdapter<Entry>(entryList.iterator()) {
					
					@Override
					protected IModel<Entry> model(Entry object) {
						return new CompoundPropertyModel<Entry>(object);
					}
				};
				return mia;
			}

			@Override
			protected void populateItem(Item<Entry> item) {
				IModel<Entry> model = item.getModel();
				
				item.add(new TextField<String>("textOne", new
PropertyModel<String>(model, "value1")));
				item.add(new TextField<String>("textTwo", new
PropertyModel<String>(model, "value2")));
			}

		};
		
		form.add(refreshingView);

Tobi


2012/7/17 Josh Kamau <jo...@gmail.com>:
> Tobi ;
>
> May be you can paste some code to show how you are constructing the
> forms...
>
> I believe if you just add the validators to the components and then submit
> the forms, it just works..
>
> Josh.
>
> On Tue, Jul 17, 2012 at 10:22 AM, Tobias Knierim <
> tobias.knierim@googlemail.com> wrote:
>
>> Hi Josh,
>>
>> The whole view is wrapped in one form.
>>
>> Greetings
>> Tobi
>>
>> Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:
>>
>> > Hi ;
>> >
>> > Is the whole listview wrapped in 1 form or there is a form for each row?
>> >
>> > Josh.
>> >
>> > On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
>> > tobias.knierim@googlemail.com> wrote:
>> >
>> >> Hi there,
>> >> I'm new to wicket and have a problem I can't find out for myself.
>> >> Maybe some of you can help me out with this.
>> >>
>> >> I have a refreshingview with input fields each row. I can add new rows
>> >> on click of a button, but when I submit the form, I want to validate 2
>> >> input fields from different rows. Everything I tried so far hasn't
>> >> worked out, because I was only able to validate values from one row.
>> >>
>> >> Is it even possible to do something like this?
>> >>
>> >>
>> >> Greetings
>> >> Tobi
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@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
>>
>>

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


Re: Validating form components in a refreshing view

Posted by Josh Kamau <jo...@gmail.com>.
Tobi ;

May be you can paste some code to show how you are constructing the
forms...

I believe if you just add the validators to the components and then submit
the forms, it just works..

Josh.

On Tue, Jul 17, 2012 at 10:22 AM, Tobias Knierim <
tobias.knierim@googlemail.com> wrote:

> Hi Josh,
>
> The whole view is wrapped in one form.
>
> Greetings
> Tobi
>
> Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:
>
> > Hi ;
> >
> > Is the whole listview wrapped in 1 form or there is a form for each row?
> >
> > Josh.
> >
> > On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
> > tobias.knierim@googlemail.com> wrote:
> >
> >> Hi there,
> >> I'm new to wicket and have a problem I can't find out for myself.
> >> Maybe some of you can help me out with this.
> >>
> >> I have a refreshingview with input fields each row. I can add new rows
> >> on click of a button, but when I submit the form, I want to validate 2
> >> input fields from different rows. Everything I tried so far hasn't
> >> worked out, because I was only able to validate values from one row.
> >>
> >> Is it even possible to do something like this?
> >>
> >>
> >> Greetings
> >> Tobi
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@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: Validating form components in a refreshing view

Posted by Tobias Knierim <to...@googlemail.com>.
Hi Josh,

The whole view is wrapped in one form.

Greetings
Tobi

Am 17.07.2012 um 09:04 schrieb Josh Kamau <jo...@gmail.com>:

> Hi ;
>
> Is the whole listview wrapped in 1 form or there is a form for each row?
>
> Josh.
>
> On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
> tobias.knierim@googlemail.com> wrote:
>
>> Hi there,
>> I'm new to wicket and have a problem I can't find out for myself.
>> Maybe some of you can help me out with this.
>>
>> I have a refreshingview with input fields each row. I can add new rows
>> on click of a button, but when I submit the form, I want to validate 2
>> input fields from different rows. Everything I tried so far hasn't
>> worked out, because I was only able to validate values from one row.
>>
>> Is it even possible to do something like this?
>>
>>
>> Greetings
>> Tobi
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@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: Validating form components in a refreshing view

Posted by Josh Kamau <jo...@gmail.com>.
Hi ;

Is the whole listview wrapped in 1 form or there is a form for each row?

Josh.

On Tue, Jul 17, 2012 at 10:02 AM, Tobias Knierim <
tobias.knierim@googlemail.com> wrote:

> Hi there,
> I'm new to wicket and have a problem I can't find out for myself.
> Maybe some of you can help me out with this.
>
> I have a refreshingview with input fields each row. I can add new rows
> on click of a button, but when I submit the form, I want to validate 2
> input fields from different rows. Everything I tried so far hasn't
> worked out, because I was only able to validate values from one row.
>
> Is it even possible to do something like this?
>
>
> Greetings
> Tobi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>