Problem updating item in IndexedContainer

I am trying to update one property value in an IndexedContainer with code

	  		[code]

Object itemId = myItems.getIdByIndex(index);
Item vitem = myItems.getItem(itemId);
MyItem mitem = (MyItem )( vitem );

                            public class MyItem implements Item,Item.PropertySetChangeNotifier{}

[/code]

I get the error

com.vaadin.data.util.IndexedContainer$IndexedContainerItem cannot be cast to ca.rbh.vaadin.views.MyItem

I tried to fix this by adding a constructor

                    [code]

public MyItem(Item vitem){}
[/code]

but then I get similar class cast errors in Property.

MyItem class cannot implement com.vaadin.data.util.IndexedContainer$IndexedContainerItem because it is not public.

How should I access MyItem s in an IndexedContainer ?

I don’t really know what your MyItem really is, so it’s hard to say anything useful about it, but can’t you just handle the item as Item?

Object itemId = myItems.getIdByIndex(index);
Item vitem = myItems.getItem(itemId);
vitem.getItemProperty("myProperty").setValue(newValue);

Thanks. You are right.

I don’t care what kind of item it is as long as it has the property I need. But in any case, the Container Interface puts pretty strict rules on what it contains, quote:

All Items in the Container must include the same number of Properties
 * 
 * All Items in the Container must include the same Property ID sets (see 
 *       Item.getItemPropertyIds()).
 *       
 * all Properties in the Items corresponding to the same Property ID must 
 *      have the same data type.
 *      
 * All Items within a container are uniquely identified by their non-null 
 * ids 

No, I didn’t get it yet.

Here is one class, an item holding its own properties which get ‘wired’ (hopefully) to their viewer.

public class ThumbnailItem extends PropertysetItem{
	StringProperty location = new StringProperty();
	StringProperty type = new StringProperty();
	StringProperty value = new StringProperty();

	static public final String LID = "location";
	static public final String TID = "type";
	static public final String VID = "value";
	
		public ThumbnailItem(String atype, String alocation, String avalue){
		super();
		id = atype+alocation;
		type.setValue(atype);
		location.setValue(alocation);
		value.setValue(avalue);
		addItemProperty( LID, location); // only using location as reference
		addItemProperty( TID, type);
		addItemProperty( VID, value);
	}
 ....

I create an instance of this, put it in a collection, then read it right back using the item as ID.

[code]

thumitem = new ThumbnailItem( child.getStringType(), child.getLocation(), value);
if( thItems.addItem( thumitem ) == null ) // ID is the item
log.error(“makeItems”,"Could not add item " + thumitem.getID());

//debug
for(int index=0;index<thItems.size();index++){
	Object itemId = thItems.getIdByIndex(index); // get an ID == the item

	Item vitem = thItems.getItem( itemId );  // <<<<<<<<<<<<<<<<<<< this alternative does not work
            // what I get returned is a IndexededContainer.IndexContainerItem holding the correct index
            // but when I get to typeValue, it holds null


	//Item vitem = (Item)itemId; // <<<<<<<<<<<<<<<<<<<<<<<<<<<< this alternative works

	Property prop = vitem.getItemProperty(ThumbnailItem.LID);
       String typeValue = (String)prop.getValue();
       System.err.println("typeValue "  + typeValue);
	}

[/code]

What am I doing wrong?

I want my collections to bind to tables, etc and work as expected.

As far as I can see, if I use Pojos instead, they are not bound for update, so not suitable without rebinding.