You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jOki <jo...@gmail.com> on 2010/06/18 18:29:23 UTC

ListView + dynamic rows: always remove last row...

Hi!!

Im trying to implement a dynamic Form, where you can add textfields and
remove as you want. The add button works fine, but the remove button always
remove the last testfield and not the selected field. For example:

Textfield1 add remove
Textfield2 add remove
Textfield3 add remove

click on remove (row textfield2) and Textfield3 is removed. It should remove
Textfield2, doesnt it?


Some code:

public class KeywordObject implements Serializable {
        private static final long serialVersionUID = 1L;
        private String keyword;
   
        public void setKeyword(String keyword) {
            this.keyword = keyword;
        }

        public String getKeyword() {
            return this.keyword;
        }
    }

And in the form...

List<KeywordObject> keyList = new ArrayList<KeywordObject>();
keyList.add(new KeywordObject());

final ListView keywordView = new ListView("keywordView", keyList) {

                @Override
                protected void populateItem(final ListItem item) {
                    KeywordObject model = (KeywordObject)
item.getModelObject();
                    item.add(new TextField("keyword", new
PropertyModel(model, "keyword")));

                    // keyword add link
                    Link addKeyword = new Link("addKeyword",
item.getModel()) {

                        @Override
                        public void onClick() {
                            keyList.add(new KeywordObject());
                        }
                    };

                    // keyword remove link
                    Link removeKeyword = new Link("removeKeyword",
item.getModel()) {

                        @Override
                        public void onClick() {
                            KeywordObject selected = (KeywordObject)
getModelObject();
                            keyList.remove(selected);
                        }
                    };

                    item.add(addKeyword);
                    item.add(removeKeyword);
                }
            };

            add(keywordView);
            keywordView.setReuseItems(true);


Im getting crazy about that...

Thanks.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2260480.html
Sent from the Wicket - User 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: ListView + dynamic rows: always remove last row...

Posted by James Carman <ja...@carmanconsulting.com>.
What kind of objects are they?  For entities, I use a uuid for the primary
key and it's assigned when the object is created.  That way you make
equals/hashcode based on the uuid so that everything stays consistent

On Jun 19, 2010 1:42 PM, "jOki" <jo...@gmail.com> wrote:


Hi,

I tried with/without setReuseItems and the behaviour is the same.

I think you can be right with equals/hashcode not being implemented
correctly...

I tried another time with a List<String> with different values and its
working...

I tried as well to implement these methods (equals/hashcode) in my code but
it doesnt work.

How can I differentiate objects even if when they are added (they are
textfields) they just have empty values????

Thanks for the help!
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2261292.html

Sent from the Wicket - User mailing list archive at Nabble.com.

-----------------------------------...

Re: ListView + dynamic rows: always remove last row...

Posted by jOki <jo...@gmail.com>.
Hi,

I tried with/without setReuseItems and the behaviour is the same.

I think you can be right with equals/hashcode not being implemented
correctly...

I tried another time with a List<String> with different values and its
working...

I tried as well to implement these methods (equals/hashcode) in my code but
it doesnt work.

How can I differentiate objects even if when they are added (they are
textfields) they just have empty values????

Thanks for the help!
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2261292.html
Sent from the Wicket - User 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: ListView + dynamic rows: always remove last row...

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Also, is the item you're trying to remove a null in the list?  Or, is it a
problem with equals/hashcode not being implemented correctly?  I just fixed
a bug in ListView this week with the remove link and move up/down links.  It
was relying on the equals of the model object of the item to find which to
remove.  Now it removes by index.  But I think James is on to the right
answer for your case.

On Sat, Jun 19, 2010 at 7:50 AM, James Carman <ja...@carmanconsulting.com>wrote:

> Just as a test, turn off the reuseItems property.  See what happens.
>
> On Sat, Jun 19, 2010 at 5:04 AM, jOki <jo...@gmail.com> wrote:
> >
> > Even Im trying to implement the remove link as:
> >
> >  - item.add(removeLink("removeKeyword", item));
> >
> > and it doesnt work... always remove the last row...
> >
> >
> > --
> > View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2261045.html
> > Sent from the Wicket - User 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
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: ListView + dynamic rows: always remove last row...

Posted by James Carman <ja...@carmanconsulting.com>.
Just as a test, turn off the reuseItems property.  See what happens.

On Sat, Jun 19, 2010 at 5:04 AM, jOki <jo...@gmail.com> wrote:
>
> Even Im trying to implement the remove link as:
>
>  - item.add(removeLink("removeKeyword", item));
>
> and it doesnt work... always remove the last row...
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2261045.html
> Sent from the Wicket - User 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: ListView + dynamic rows: always remove last row...

Posted by jOki <jo...@gmail.com>.
Even Im trying to implement the remove link as:

 - item.add(removeLink("removeKeyword", item));

and it doesnt work... always remove the last row...


-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/ListView-dynamic-rows-always-remove-last-row-tp2260480p2261045.html
Sent from the Wicket - User 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: ListView + dynamic rows: always remove last row...

Posted by Erik van Oosten <e....@grons.nl>.
Try to use the RemoveLink that is available as inner class of ListView.

Regards,
     Erik.


Op 18-06-10 18:29, jOki wrote:
> Hi!!
>
> Im trying to implement a dynamic Form, where you can add textfields and
> remove as you want. The add button works fine, but the remove button always
> remove the last testfield and not the selected field. For example:
>
> Textfield1 add remove
> Textfield2 add remove
> Textfield3 add remove
>
> click on remove (row textfield2) and Textfield3 is removed. It should remove
> Textfield2, doesnt it?
>
>
> Some code:
>
> public class KeywordObject implements Serializable {
>          private static final long serialVersionUID = 1L;
>          private String keyword;
>
>          public void setKeyword(String keyword) {
>              this.keyword = keyword;
>          }
>
>          public String getKeyword() {
>              return this.keyword;
>          }
>      }
>
> And in the form...
>
> List<KeywordObject>  keyList = new ArrayList<KeywordObject>();
> keyList.add(new KeywordObject());
>
> final ListView keywordView = new ListView("keywordView", keyList) {
>
>                  @Override
>                  protected void populateItem(final ListItem item) {
>                      KeywordObject model = (KeywordObject)
> item.getModelObject();
>                      item.add(new TextField("keyword", new
> PropertyModel(model, "keyword")));
>
>                      // keyword add link
>                      Link addKeyword = new Link("addKeyword",
> item.getModel()) {
>
>                          @Override
>                          public void onClick() {
>                              keyList.add(new KeywordObject());
>                          }
>                      };
>
>                      // keyword remove link
>                      Link removeKeyword = new Link("removeKeyword",
> item.getModel()) {
>
>                          @Override
>                          public void onClick() {
>                              KeywordObject selected = (KeywordObject)
> getModelObject();
>                              keyList.remove(selected);
>                          }
>                      };
>
>                      item.add(addKeyword);
>                      item.add(removeKeyword);
>                  }
>              };
>
>              add(keywordView);
>              keywordView.setReuseItems(true);
>
>
> Im getting crazy about that...
>
> Thanks.
>    


-- 
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/


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