You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Hamilton <dh...@hermitagelighting.com> on 2010/04/16 15:48:33 UTC

Repeating form on a page

I am new to Wicket (and have had great help from this community so far -
thank you). My question here is that I'm trying to setup a simple
contact form where a person may have zero or more contacts. My solution
is to make the contact info a form within a panel. However, I need to
repeat the panel form on the page for each contact (represented by a
POJO I can bind to the form elements).  I will provide and "add" button
at the bottom of the list to allow them to re-submit the page and add a
new empty object bound to a new form element. 

 

  So my question is really two questions.

 

1)      Is this best approach for this situation?

2)      If it is, how do I bind each POJO on the list to a unique form
instance? 

 

The goal is to allow each contact to be individually edited  and saved. 

 

Any help is greatly appreciated.

 

Thanks, 

 

David Hamilton

Web Coordinator 

(615) 843-3337

Hermitage Lighting Gallery

www.hermitagelighting.com

 


********************************************
Keep it Green! To help protect the environment, please
only print this email if necessary. 
Printing email can cost more than you think. 
Learn more on our website: http://www.hermitagelighting.com/printing_email.php

The information transmitted in this email is 
intended solely for the individual or entity 
to which it is addressed and may contain 
confidential and/or privileged material. 
Any review, retransmission, dissemination or
other use of or taking action in reliance 
upon this information by persons or entities 
other than the intended recipient is prohibited. 
If you have received this email in error please 
immediately notify us by reply email to the sender. 
You must destroy the original material and its contents from any computer. 
******************************************** 


Re: Repeating form on a page

Posted by James Carman <jc...@carmanconsulting.com>.
The forms are all based on models.  So, just make sure you use a
different model for each form.  I'd look into ListView, perhaps.

On Fri, Apr 16, 2010 at 9:48 AM, David Hamilton
<dh...@hermitagelighting.com> wrote:
> I am new to Wicket (and have had great help from this community so far -
> thank you). My question here is that I'm trying to setup a simple
> contact form where a person may have zero or more contacts. My solution
> is to make the contact info a form within a panel. However, I need to
> repeat the panel form on the page for each contact (represented by a
> POJO I can bind to the form elements).  I will provide and "add" button
> at the bottom of the list to allow them to re-submit the page and add a
> new empty object bound to a new form element.
>
>
>
>  So my question is really two questions.
>
>
>
> 1)      Is this best approach for this situation?
>
> 2)      If it is, how do I bind each POJO on the list to a unique form
> instance?
>
>
>
> The goal is to allow each contact to be individually edited  and saved.
>
>
>
> Any help is greatly appreciated.
>
>
>
> Thanks,
>
>
>
> David Hamilton
>
> Web Coordinator
>
> (615) 843-3337
>
> Hermitage Lighting Gallery
>
> www.hermitagelighting.com
>
>
>
>
> ********************************************
> Keep it Green! To help protect the environment, please
> only print this email if necessary.
> Printing email can cost more than you think.
> Learn more on our website: http://www.hermitagelighting.com/printing_email.php
>
> The information transmitted in this email is
> intended solely for the individual or entity
> to which it is addressed and may contain
> confidential and/or privileged material.
> Any review, retransmission, dissemination or
> other use of or taking action in reliance
> upon this information by persons or entities
> other than the intended recipient is prohibited.
> If you have received this email in error please
> immediately notify us by reply email to the sender.
> You must destroy the original material and its contents from any computer.
> ********************************************
>
>

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


Re: Repeating form on a page

Posted by Igor Vaynberg <ig...@gmail.com>.
this may give you some ideas

http://wicketinaction.com/2008/10/building-a-listeditor-form-component/

-igor

On Fri, Apr 16, 2010 at 6:48 AM, David Hamilton
<dh...@hermitagelighting.com> wrote:
> I am new to Wicket (and have had great help from this community so far -
> thank you). My question here is that I'm trying to setup a simple
> contact form where a person may have zero or more contacts. My solution
> is to make the contact info a form within a panel. However, I need to
> repeat the panel form on the page for each contact (represented by a
> POJO I can bind to the form elements).  I will provide and "add" button
> at the bottom of the list to allow them to re-submit the page and add a
> new empty object bound to a new form element.
>
>
>
>  So my question is really two questions.
>
>
>
> 1)      Is this best approach for this situation?
>
> 2)      If it is, how do I bind each POJO on the list to a unique form
> instance?
>
>
>
> The goal is to allow each contact to be individually edited  and saved.
>
>
>
> Any help is greatly appreciated.
>
>
>
> Thanks,
>
>
>
> David Hamilton
>
> Web Coordinator
>
> (615) 843-3337
>
> Hermitage Lighting Gallery
>
> www.hermitagelighting.com
>
>
>
>
> ********************************************
> Keep it Green! To help protect the environment, please
> only print this email if necessary.
> Printing email can cost more than you think.
> Learn more on our website: http://www.hermitagelighting.com/printing_email.php
>
> The information transmitted in this email is
> intended solely for the individual or entity
> to which it is addressed and may contain
> confidential and/or privileged material.
> Any review, retransmission, dissemination or
> other use of or taking action in reliance
> upon this information by persons or entities
> other than the intended recipient is prohibited.
> If you have received this email in error please
> immediately notify us by reply email to the sender.
> You must destroy the original material and its contents from any computer.
> ********************************************
>
>

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


Re: Repeating form on a page

Posted by heikki <tr...@gmail.com>.
OK ! Indeed, this solves it, and now all's perfect.

Thank you so much !

Kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Repeating-form-on-a-page-tp2002098p3722228.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: Repeating form on a page

Posted by Sven Meier <sv...@meiers.net>.
Hi,

it really doesn't matter which repeater, but ListView is probably the 
most easy to use.

     protected void populateItem(ListItem item) {
         add(new AForm(...);
     }

Typical error each of us has done wrong when using repeaters for the 
first time. It has to be:

         item.add(new AForm(...);

Hope this helps
Sven

On 07/29/2011 02:50 PM, heikki wrote:
> hello,
>
> despite searching around I haven't found a good working example/explanation
> of how to create a page where a form is repeated for each element in a
> collection. (I found some info on using repeaters inside forms, but that is
> a reverse situation).
>
> Earlier in this thread there's the advice to use RefreshingView instead of
> ListView. Is this good advice? What is the difference between them in this
> scenario where forms should be repeated?
>
> I tried doing it as below, but it causes a runtime exception. Can anyone
> point out what I'm doing wrong and how it should be done?
>
> The exception I'm getting is
>
> Last cause: Unable to find component with id 'aForm' in [ListItem [Component
> id = 0]]
> 	Expected: 'a-list:0.aForm'.
> 	Found with similar names: 'a-list:aForm'
>
> The code is
>
>          <div wicket:id="a-list">
>              <form wicket:id="aForm">
>                  <input wicket:id="myproperty" type="text"/>
>                  <div>
>                      <input wicket:id="save" type="submit" value="Save"/>
>                      <input wicket:id="remove" type="submit" value="Remove"/>
>                  </div>
>              </form>
>          </div>
>
>      private ListView aList = new ListView("a-list", aDAO.retrieveAll()) {
>              @Override
>              protected void populateItem(ListItem item) {
>                  final A a = (A) item.getModelObject();
>                  add(new AForm("aForm",
>                          new CompoundPropertyModel(new
> LoadableDetachableModel() {
>                              @Override
>                              protected Object load() {
>                                  return a;
>                              }
>                          })
>                  ));
>              }};
>   private class AForm extends Form {
>          public AForm(String id, IModel m) {
>              super(id, m);
>              TextField myProperty= new TextField("myproperty");
>              add(myProperty);
>              add(new Button("save") {
>                  public void onSubmit() {
>                      A selected = (A) getForm().getModelObject();
>                      ADAO.save(selected);
>                      setResponsePage(APage.class);
>                  }
>              });
>              add(
>                      new Button("remove") {
>                          @Override
>                          public void onSubmit() {
>                              A selected = (A) getForm().getModelObject();
>                              ADAO.delete(selected);
>                              setResponsePage(APage.class);
>                          }
>                      });
>          }
>      }
>
> thanks in advance for your reply,
> kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Repeating-form-on-a-page-tp2002098p3703919.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
>


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


Re: Repeating form on a page

Posted by heikki <tr...@gmail.com>.
hello,

despite searching around I haven't found a good working example/explanation
of how to create a page where a form is repeated for each element in a
collection. (I found some info on using repeaters inside forms, but that is
a reverse situation).

Earlier in this thread there's the advice to use RefreshingView instead of
ListView. Is this good advice? What is the difference between them in this
scenario where forms should be repeated?

I tried doing it as below, but it causes a runtime exception. Can anyone
point out what I'm doing wrong and how it should be done?

The exception I'm getting is

Last cause: Unable to find component with id 'aForm' in [ListItem [Component
id = 0]]
	Expected: 'a-list:0.aForm'.
	Found with similar names: 'a-list:aForm'

The code is

        <div wicket:id="a-list">
            <form wicket:id="aForm">
                <input wicket:id="myproperty" type="text"/>
                <div>
                    <input wicket:id="save" type="submit" value="Save"/>
                    <input wicket:id="remove" type="submit" value="Remove"/>
                </div>
            </form>
        </div>

    private ListView aList = new ListView("a-list", aDAO.retrieveAll()) {
            @Override
            protected void populateItem(ListItem item) {
                final A a = (A) item.getModelObject();
                add(new AForm("aForm",
                        new CompoundPropertyModel(new
LoadableDetachableModel() {
                            @Override
                            protected Object load() {
                                return a;
                            }
                        })
                ));
            }};
 private class AForm extends Form {
        public AForm(String id, IModel m) {
            super(id, m);
            TextField myProperty= new TextField("myproperty");
            add(myProperty);
            add(new Button("save") {
                public void onSubmit() {
                    A selected = (A) getForm().getModelObject();
                    ADAO.save(selected);
                    setResponsePage(APage.class);
                }
            });
            add(
                    new Button("remove") {
                        @Override
                        public void onSubmit() {
                            A selected = (A) getForm().getModelObject();
                            ADAO.delete(selected);
                            setResponsePage(APage.class);
                        }
                    });
        }
    }

thanks in advance for your reply,
kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Repeating-form-on-a-page-tp2002098p3703919.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: Repeating form on a page

Posted by Ben Tilford <be...@gmail.com>.
Would a FormComponentPanel work?
http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/FormComponentPanel.html

On Fri, Apr 16, 2010 at 4:48 PM, David Hamilton <
dhamilton@hermitagelighting.com> wrote:

> Thanks for the great response! I will look at RefreshingView, but right now
> I'm considering yet another possibility.
> I'm think of using a display-only ListView for existing items with an edit
> button to populate a modal dialog. I have yet to get to the Modal dialog
> part so I'll have to report back on how well that works :).
>
> Thanks,
>
> David
>
> -----Original Message-----
> From: Xavier López [mailto:xavilope@gmail.com]
> Sent: Friday, April 16, 2010 9:33 AM
> To: users@wicket.apache.org
> Subject: Re: Repeating form on a page
>
> Hi,
>
> I've been through a similar issue recently, also with a 'remove' button to
> delete elements from the list. I ended up using RefreshingView (that's the
> one I'd reccomend), and it worked nicely.
>
> However I'll expose the various solutions I've gone through, hoping to
> provide some background on the subject. I'd also be grateful on
> observations
> and comments on these, because I'm sure I'm missing something and there are
> still some aspects of these repeaters that I don't understand, so probably
> part of these thoughts are wrong :)
>
> In the first place, I used a ListView repeater. When clicking the 'add new'
> button, however, I found that all unsaved input entered on the other list
> elements was lost. That's because ListView refreshes the entire List with
> the backing Model objects in it's Model<List>, and models were not being
> updated, as forms were not being submitted. So, I had to make the 'add new'
> link a submit button (skipping default form processing in order to avoid
> validation errors on incomplete data). However, to my surprise, same thing
> keeped happening (same for the delete button). Later on, I found about
> 'ListView#setReuseItems(boolean)', which solved the problem. But to my
> despair, the delete button always deleted the last element from the List. I
> still do not understand why, and still don't know what is 'reuseItems'
> really doing. (Any hints on that one?)
>
> Then, I was advised to use RefreshingView, and things were moreover the
> same, only that instead of having a Model<List> given to the repeater, an
> Iterator<Model> had to be provided in an overriden method. In this case, a
> ModelsEqual ReuseItemStrategy had to be provided in order to keep the
> unsaved inputs in the forms when adding/removing.
>
>
> As a last appreciation, I have to say I hoped there was a specific
> component
> addressing this behavior, being it a fairly common arrangement... If one
> day
> I fully understand this I'd be happy to implement one myself, even if only
> for the sake of clarity in my code ;)
>
> Thanks,
> Xavier
>
> 2010/4/16 David Hamilton <dh...@hermitagelighting.com>
>
> > I am new to Wicket (and have had great help from this community so far -
> > thank you). My question here is that I'm trying to setup a simple
> > contact form where a person may have zero or more contacts. My solution
> > is to make the contact info a form within a panel. However, I need to
> > repeat the panel form on the page for each contact (represented by a
> > POJO I can bind to the form elements).  I will provide and "add" button
> > at the bottom of the list to allow them to re-submit the page and add a
> > new empty object bound to a new form element.
> >
> >
> >
> >  So my question is really two questions.
> >
> >
> >
> > 1)      Is this best approach for this situation?
> >
> > 2)      If it is, how do I bind each POJO on the list to a unique form
> > instance?
> >
> >
> >
> > The goal is to allow each contact to be individually edited  and saved.
> >
> >
> >
> > Any help is greatly appreciated.
> >
> >
> >
> > Thanks,
> >
> >
> >
> > David Hamilton
> >
> > Web Coordinator
> >
> > (615) 843-3337
> >
> > Hermitage Lighting Gallery
> >
> > www.hermitagelighting.com
> >
> >
> >
> >
> > ********************************************
> > Keep it Green! To help protect the environment, please
> > only print this email if necessary.
> > Printing email can cost more than you think.
> > Learn more on our website:
> > http://www.hermitagelighting.com/printing_email.php
> >
> > The information transmitted in this email is
> > intended solely for the individual or entity
> > to which it is addressed and may contain
> > confidential and/or privileged material.
> > Any review, retransmission, dissemination or
> > other use of or taking action in reliance
> > upon this information by persons or entities
> > other than the intended recipient is prohibited.
> > If you have received this email in error please
> > immediately notify us by reply email to the sender.
> > You must destroy the original material and its contents from any
> computer.
> > ********************************************
> >
> >
>
>
> --
> "Klein bottle for rent--inquire within."
>
> ********************************************
> Keep it Green! To help protect the environment, please
> only print this email if necessary.
> Printing email can cost more than you think.
> Learn more on our website:
> http://www.hermitagelighting.com/printing_email.php
>
> The information transmitted in this email is
> intended solely for the individual or entity
> to which it is addressed and may contain
> confidential and/or privileged material.
> Any review, retransmission, dissemination or
> other use of or taking action in reliance
> upon this information by persons or entities
> other than the intended recipient is prohibited.
> If you have received this email in error please
> immediately notify us by reply email to the sender.
> You must destroy the original material and its contents from any computer.
> ********************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

RE: Repeating form on a page

Posted by David Hamilton <dh...@hermitagelighting.com>.
Thanks for the great response! I will look at RefreshingView, but right now I'm considering yet another possibility. 
I'm think of using a display-only ListView for existing items with an edit button to populate a modal dialog. I have yet to get to the Modal dialog part so I'll have to report back on how well that works :).

Thanks,

David 

-----Original Message-----
From: Xavier López [mailto:xavilope@gmail.com] 
Sent: Friday, April 16, 2010 9:33 AM
To: users@wicket.apache.org
Subject: Re: Repeating form on a page

Hi,

I've been through a similar issue recently, also with a 'remove' button to
delete elements from the list. I ended up using RefreshingView (that's the
one I'd reccomend), and it worked nicely.

However I'll expose the various solutions I've gone through, hoping to
provide some background on the subject. I'd also be grateful on observations
and comments on these, because I'm sure I'm missing something and there are
still some aspects of these repeaters that I don't understand, so probably
part of these thoughts are wrong :)

In the first place, I used a ListView repeater. When clicking the 'add new'
button, however, I found that all unsaved input entered on the other list
elements was lost. That's because ListView refreshes the entire List with
the backing Model objects in it's Model<List>, and models were not being
updated, as forms were not being submitted. So, I had to make the 'add new'
link a submit button (skipping default form processing in order to avoid
validation errors on incomplete data). However, to my surprise, same thing
keeped happening (same for the delete button). Later on, I found about
'ListView#setReuseItems(boolean)', which solved the problem. But to my
despair, the delete button always deleted the last element from the List. I
still do not understand why, and still don't know what is 'reuseItems'
really doing. (Any hints on that one?)

Then, I was advised to use RefreshingView, and things were moreover the
same, only that instead of having a Model<List> given to the repeater, an
Iterator<Model> had to be provided in an overriden method. In this case, a
ModelsEqual ReuseItemStrategy had to be provided in order to keep the
unsaved inputs in the forms when adding/removing.


As a last appreciation, I have to say I hoped there was a specific component
addressing this behavior, being it a fairly common arrangement... If one day
I fully understand this I'd be happy to implement one myself, even if only
for the sake of clarity in my code ;)

Thanks,
Xavier

2010/4/16 David Hamilton <dh...@hermitagelighting.com>

> I am new to Wicket (and have had great help from this community so far -
> thank you). My question here is that I'm trying to setup a simple
> contact form where a person may have zero or more contacts. My solution
> is to make the contact info a form within a panel. However, I need to
> repeat the panel form on the page for each contact (represented by a
> POJO I can bind to the form elements).  I will provide and "add" button
> at the bottom of the list to allow them to re-submit the page and add a
> new empty object bound to a new form element.
>
>
>
>  So my question is really two questions.
>
>
>
> 1)      Is this best approach for this situation?
>
> 2)      If it is, how do I bind each POJO on the list to a unique form
> instance?
>
>
>
> The goal is to allow each contact to be individually edited  and saved.
>
>
>
> Any help is greatly appreciated.
>
>
>
> Thanks,
>
>
>
> David Hamilton
>
> Web Coordinator
>
> (615) 843-3337
>
> Hermitage Lighting Gallery
>
> www.hermitagelighting.com
>
>
>
>
> ********************************************
> Keep it Green! To help protect the environment, please
> only print this email if necessary.
> Printing email can cost more than you think.
> Learn more on our website:
> http://www.hermitagelighting.com/printing_email.php
>
> The information transmitted in this email is
> intended solely for the individual or entity
> to which it is addressed and may contain
> confidential and/or privileged material.
> Any review, retransmission, dissemination or
> other use of or taking action in reliance
> upon this information by persons or entities
> other than the intended recipient is prohibited.
> If you have received this email in error please
> immediately notify us by reply email to the sender.
> You must destroy the original material and its contents from any computer.
> ********************************************
>
>


-- 
"Klein bottle for rent--inquire within."

********************************************
Keep it Green! To help protect the environment, please
only print this email if necessary. 
Printing email can cost more than you think. 
Learn more on our website: http://www.hermitagelighting.com/printing_email.php

The information transmitted in this email is 
intended solely for the individual or entity 
to which it is addressed and may contain 
confidential and/or privileged material. 
Any review, retransmission, dissemination or
other use of or taking action in reliance 
upon this information by persons or entities 
other than the intended recipient is prohibited. 
If you have received this email in error please 
immediately notify us by reply email to the sender. 
You must destroy the original material and its contents from any computer. 
******************************************** 


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


Re: Repeating form on a page

Posted by Xavier López <xa...@gmail.com>.
Hi,

I've been through a similar issue recently, also with a 'remove' button to
delete elements from the list. I ended up using RefreshingView (that's the
one I'd reccomend), and it worked nicely.

However I'll expose the various solutions I've gone through, hoping to
provide some background on the subject. I'd also be grateful on observations
and comments on these, because I'm sure I'm missing something and there are
still some aspects of these repeaters that I don't understand, so probably
part of these thoughts are wrong :)

In the first place, I used a ListView repeater. When clicking the 'add new'
button, however, I found that all unsaved input entered on the other list
elements was lost. That's because ListView refreshes the entire List with
the backing Model objects in it's Model<List>, and models were not being
updated, as forms were not being submitted. So, I had to make the 'add new'
link a submit button (skipping default form processing in order to avoid
validation errors on incomplete data). However, to my surprise, same thing
keeped happening (same for the delete button). Later on, I found about
'ListView#setReuseItems(boolean)', which solved the problem. But to my
despair, the delete button always deleted the last element from the List. I
still do not understand why, and still don't know what is 'reuseItems'
really doing. (Any hints on that one?)

Then, I was advised to use RefreshingView, and things were moreover the
same, only that instead of having a Model<List> given to the repeater, an
Iterator<Model> had to be provided in an overriden method. In this case, a
ModelsEqual ReuseItemStrategy had to be provided in order to keep the
unsaved inputs in the forms when adding/removing.


As a last appreciation, I have to say I hoped there was a specific component
addressing this behavior, being it a fairly common arrangement... If one day
I fully understand this I'd be happy to implement one myself, even if only
for the sake of clarity in my code ;)

Thanks,
Xavier

2010/4/16 David Hamilton <dh...@hermitagelighting.com>

> I am new to Wicket (and have had great help from this community so far -
> thank you). My question here is that I'm trying to setup a simple
> contact form where a person may have zero or more contacts. My solution
> is to make the contact info a form within a panel. However, I need to
> repeat the panel form on the page for each contact (represented by a
> POJO I can bind to the form elements).  I will provide and "add" button
> at the bottom of the list to allow them to re-submit the page and add a
> new empty object bound to a new form element.
>
>
>
>  So my question is really two questions.
>
>
>
> 1)      Is this best approach for this situation?
>
> 2)      If it is, how do I bind each POJO on the list to a unique form
> instance?
>
>
>
> The goal is to allow each contact to be individually edited  and saved.
>
>
>
> Any help is greatly appreciated.
>
>
>
> Thanks,
>
>
>
> David Hamilton
>
> Web Coordinator
>
> (615) 843-3337
>
> Hermitage Lighting Gallery
>
> www.hermitagelighting.com
>
>
>
>
> ********************************************
> Keep it Green! To help protect the environment, please
> only print this email if necessary.
> Printing email can cost more than you think.
> Learn more on our website:
> http://www.hermitagelighting.com/printing_email.php
>
> The information transmitted in this email is
> intended solely for the individual or entity
> to which it is addressed and may contain
> confidential and/or privileged material.
> Any review, retransmission, dissemination or
> other use of or taking action in reliance
> upon this information by persons or entities
> other than the intended recipient is prohibited.
> If you have received this email in error please
> immediately notify us by reply email to the sender.
> You must destroy the original material and its contents from any computer.
> ********************************************
>
>


-- 
"Klein bottle for rent--inquire within."