You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Lan Boon Ping <bo...@gmail.com> on 2008/02/14 05:05:54 UTC

Doubt about getList().indexOf() usage in ListView.moveUpLink, moveDownLink, removeLink

Hi,

Taking a look at ListView.moveUpLink as example, I doubt that this
getList().indexOf() will return a correct index if we have duplicate
items with same identity in getList(). Should not it uses
item.getIndex() instead?

    public final Link moveUpLink(final String id, final ListItem item)
	{
		return new Link(id)
		{
			private static final long serialVersionUID = 1L;

			public void onClick()
			{
				final int index = getList().indexOf(item.getModelObject()); // use
item.getIndex() instead?

Thank You.

Regards
Boon Ping

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


Re: Doubt about getList().indexOf() usage in ListView.moveUpLink, moveDownLink, removeLink

Posted by Igor Vaynberg <ig...@gmail.com>.
because the problem is that between the time the list was rendered and
the time you click the link the underlying list might have changed, so
the move operation might be invoked on the wrong item...i think we
just chose a safer default...

-igor


On Thu, Feb 14, 2008 at 1:58 AM, Henrik Lundahl
<he...@gmail.com> wrote:
> Hi
>
>  Yes, but why can't ListItem.getIndex() be used? I can't see any
>  drawbacks, but one advantage is that you can use the same model object
>  twice in the list. It's not unlikely that I've missed something,
>  though.
>
>
>  Regards,
>  Henrik
>
>
>
>  2008/2/14, Igor Vaynberg <ig...@gmail.com>:
>
>
> > you can always roll your own link, you dont have to use the one
>  >  provided with ListView - there is nothing special it does that you
>  >  cannot do yourself. Of course we should have used item.getindex() if
>  >  there was some common interface that all items that were put in list
>  >  had to implement...but since there is no such thing we do the best we
>  >  can without it but leave you plenty of freedom to implement your own.
>  >
>  >
>  >  -igor
>  >
>  >
>  >
>  >  On Feb 13, 2008 8:05 PM, Lan Boon Ping <bo...@gmail.com> wrote:
>  >  > Hi,
>  >  >
>  >  > Taking a look at ListView.moveUpLink as example, I doubt that this
>  >  > getList().indexOf() will return a correct index if we have duplicate
>  >  > items with same identity in getList(). Should not it uses
>  >  > item.getIndex() instead?
>  >  >
>  >  >     public final Link moveUpLink(final String id, final ListItem item)
>  >  >         {
>  >  >                 return new Link(id)
>  >  >                 {
>  >  >                         private static final long serialVersionUID = 1L;
>  >  >
>  >  >                         public void onClick()
>  >  >                         {
>  >  >                                 final int index = getList().indexOf(item.getModelObject()); // use
>  >  > item.getIndex() instead?
>  >  >
>  >  > Thank You.
>  >  >
>  >  > Regards
>  >  > Boon Ping
>  >  >
>  >  > ---------------------------------------------------------------------
>  >  > 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: Doubt about getList().indexOf() usage in ListView.moveUpLink, moveDownLink, removeLink

Posted by Henrik Lundahl <he...@gmail.com>.
Hi

Yes, but why can't ListItem.getIndex() be used? I can't see any
drawbacks, but one advantage is that you can use the same model object
twice in the list. It's not unlikely that I've missed something,
though.


Regards,
Henrik



2008/2/14, Igor Vaynberg <ig...@gmail.com>:
> you can always roll your own link, you dont have to use the one
>  provided with ListView - there is nothing special it does that you
>  cannot do yourself. Of course we should have used item.getindex() if
>  there was some common interface that all items that were put in list
>  had to implement...but since there is no such thing we do the best we
>  can without it but leave you plenty of freedom to implement your own.
>
>
>  -igor
>
>
>
>  On Feb 13, 2008 8:05 PM, Lan Boon Ping <bo...@gmail.com> wrote:
>  > Hi,
>  >
>  > Taking a look at ListView.moveUpLink as example, I doubt that this
>  > getList().indexOf() will return a correct index if we have duplicate
>  > items with same identity in getList(). Should not it uses
>  > item.getIndex() instead?
>  >
>  >     public final Link moveUpLink(final String id, final ListItem item)
>  >         {
>  >                 return new Link(id)
>  >                 {
>  >                         private static final long serialVersionUID = 1L;
>  >
>  >                         public void onClick()
>  >                         {
>  >                                 final int index = getList().indexOf(item.getModelObject()); // use
>  > item.getIndex() instead?
>  >
>  > Thank You.
>  >
>  > Regards
>  > Boon Ping
>  >
>  > ---------------------------------------------------------------------
>  > 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: Doubt about getList().indexOf() usage in ListView.moveUpLink, moveDownLink, removeLink

Posted by Igor Vaynberg <ig...@gmail.com>.
you can always roll your own link, you dont have to use the one
provided with ListView - there is nothing special it does that you
cannot do yourself. Of course we should have used item.getindex() if
there was some common interface that all items that were put in list
had to implement...but since there is no such thing we do the best we
can without it but leave you plenty of freedom to implement your own.

-igor


On Feb 13, 2008 8:05 PM, Lan Boon Ping <bo...@gmail.com> wrote:
> Hi,
>
> Taking a look at ListView.moveUpLink as example, I doubt that this
> getList().indexOf() will return a correct index if we have duplicate
> items with same identity in getList(). Should not it uses
> item.getIndex() instead?
>
>     public final Link moveUpLink(final String id, final ListItem item)
>         {
>                 return new Link(id)
>                 {
>                         private static final long serialVersionUID = 1L;
>
>                         public void onClick()
>                         {
>                                 final int index = getList().indexOf(item.getModelObject()); // use
> item.getIndex() instead?
>
> Thank You.
>
> Regards
> Boon Ping
>
> ---------------------------------------------------------------------
> 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