You are calling setReuseItems method from listview. From it api:

" if you modify the listView model object, than you must manually call
listView.removeAll() in order to rebuild the ListItems. "

On Mon, Feb 8, 2010 at 10:55 AM, Alexander Monakhov <[email protected]>wrote:

> Hi, friends.
>
> Could you help me with subject?
> Here is the situation. I want to create manageable list of item, so I could
> add new items to it, update current state of each item and remove items.
> I'm using ListView for this purpose. Here is sample code that works with
> List<String> that describes items:
>
> public class ItemsPanel extends Panel {
>
> // here goes fields definition section
>
> // list of items to show
> private List<String> items;
>
> public ItemsPanel( String id ) {
>   super( id );
>
>   items = new ArrayList<String>();
>   items.add( "String 0" );
>   items.add( "String 1" );
>
>   final ListView<String> itemsList = new PropertyListView<String>(
>                "items", new PropertyModel<List<String>>( this, "items" ) )
> {
>
>      @Override
>      protected void populateItem( final ListItem<String> item ) {
>         final WebMarkupContainer baseDiv = new WebMarkupContainer( "title"
> );
>         baseDiv.add( new Label( "text", item.getModel() ) );
>
>         final WebMarkupContainer deleteImg = new WebMarkupContainer(
> "delete.arrow" );
>
>         deleteImg.add( new AjaxEventBehavior( "onClick" ) {
>
>            @Override
>            protected void onEvent( AjaxRequestTarget target ) {
>               testStrings.remove( item.getModelObject() );
>               target.addComponent( ItemsPanel.this );
>            }
>
>       });
>       baseDiv.add( deleteImg );
>
>       item.add(  baseDiv );
>    }
>
>  };
>  itemsList.setReuseItems( true );
>  itemsList.setOutputMarkupId( true );
>  add( itemsList );
>
>  add( new AjaxLink<Void>( "add" ) {
>
>    @Override
>    public void onClick( AjaxRequestTarget target ) {
>       testStrings.add( "New String " + (items.size() + 1) );
>       target.addComponent( ItemsPanel.this );
>    }
>
>  });
>
>  setOutputMarkupId( true );
> }
>
> }
>
> Markup for this class is:
> <html>
>    <body>
>        <wicket:panel>
>
>        <a wicket:id="add">Add item</a>
>        <div wicket:id="items">
>            <div wicket:id="title" class="list_title">
>                <span class="label" wicket:id="text">[Here goes a
> text]</span>
>                <img src="/img/delete.gif" class="delete_arrow"
> wicket:id="delete.arrow"/>
>                <br/>
>            </div>
>        </div>
>
>        </wicket:panel>
>    </body>
> </html>
>
>
> It'is working perfectly, but when I'm changing List<String> to
> List<CustomType>, where CustomType is custom class with appropriated info,
> when I push delete arrow last item from showed list is removed, not that
> one
> that I want to delete. But correct item is removed from backed list of
> items. I can't understand what's wrong. During debug I can see that backed
> list of items contains right set of items, but in html appeared other list
> of items.
>
> Best regards, Alexander.
>



-- 
Pedro Henrique Oliveira dos Santos

Reply via email to