You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by heikki <tr...@gmail.com> on 2011/07/29 14:50:42 UTC

Re: Repeating form on a page

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 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