Using addItem on Table - vaadin 6.7.0.rc1

Hello all,

I have been trying to migrate my code from 6.6.x to 6.70 and came across some problems… One of them is that trying to add an item to a table using additem will remove all column headers from the table and do not show any data rows… Is there any extra configuration on Tables on vaadin 6.7.0 for them to work properly?

Regards
Bruno Santos

Sounds strange as it does not show up in any of our tests. Do you have some simple example code of something that does not work?

Happens to me too on 6.7.0 release… this is the code that creates the table:


Table tbl = new Table();
tbl.setSizeFull();

tbl.setCellStyleGenerator( this );

tbl.setSelectable( false );
tbl.addListener( this );

tbl.addContainerProperty( "qty", Number.class, null, "Quantity", null, Table.ALIGN_LEFT );
tbl.addContainerProperty( "description", String.class, null, "Description", null, Table.ALIGN_LEFT );
tbl.addContainerProperty( "price", String.class, null, "Price", null, Table.ALIGN_RIGHT );

tbl.setColumnWidth( "qty", 30 );
tbl.setColumnWidth( "price", 80 );
tbl.setColumnExpandRatio( "description", 1.0f );

return tbl;

(the component generating the table is both a CellStyleGenerator and an ItemClickListener)

The code handling the table update is as follow:


tblReceipt.removeAllItems();
		
Item item = tblReceipt.addItem( line );
		
item.getItemProperty( "qty" ).setValue( Integer.valueOf( line.getQuantity() ) );
item.getItemProperty( "description" ).setValue( line.getDescription() );
item.getItemProperty( "price" ).setValue( line.getPrice().toString() );

Something i’m doing wrong?

Ticket
http://dev.vaadin.com/ticket/7731
was submitted about this.

Regards
Bruno Santos

This exact problem is happening for me in 6.7.0 final. The exact problem occurs if the following is the case:

  1. Have a page with an empty table.
  2. Some user action (like a button click) adds an item into the table.
  3. If the newly added item contains an Embedded component as a property, all the column fields get wiped out. The table does not show the newly added item.
  4. if you refresh the page with Command-R, the table shows correctly with the embedded image showing up correctly.

Pelase note, this problem does not happen if the table initially had items to begin with, and only occurs if the table is initially empty when an user event adds an item. Also, the problem seems to only happen if a component like Embedded exists in one of the fields. It does not seem to happen if I have text or layouts in the fields.

-Farhan

Hi,

Could you try with the latest nightly build and verify it works? The ticket #7731 should be fixed in SVN.

PS. Remember to recompile the widget set in case you are using add-ons or some other client side customizations.

cheers,
matti

I am using the default property container to add data to the vaadin table. I am doing so on clicking new option from the context menu. i am able to add the first item but not after that.
gridclasspath.addItemClickListener(
new ItemClickListener() {
public void itemClick(ItemClickEvent event) {
if (event.getButton()== MouseEventDetails.MouseButton.RIGHT) {
gridclasspath.select(event.getItemId());
}
}

        }
                );
        gridclasspath.addActionHandler(
                new Action.Handler()
         {
               public Action[] getActions(Object target, Object sender)
               {
                    final Action ACTION_OPEN = new Action("New");
                    final Action ACTION_PRINT = new Action("Edit");
                    final Action ACTION_DELETE = new Action("Delete");
                    final Action[] ACTIONS = new Action[]

{ ACTION_OPEN, ACTION_PRINT, ACTION_DELETE };
return ACTIONS;

               }

            @Override
            public void handleAction(Action action, Object sender,
                    Object target) {
                
                Item rowItem = gridclasspath.getItem(target);
                
                if(action.getCaption()=="New")
                {
                    TextField txt=new TextField("textfield");
                    //txt.setValue("Hey you");
                    Object newItemId = gridclasspath.addItem();
                    Item row = gridclasspath.getItem(newItemId);
                    row.getItemProperty("Classpath").setValue(txt);
                    
                    //Item item = getItem(gridclasspath.addItem());
                    gridclasspath.addItem(new Object[]{txt},newItemId);
                    Button b = new Button("submit");
                    addComponent(b);
                    b.setClickShortcut(KeyCode.ENTER);                    

                    //b.setVisible(false);

                    b.addClickListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event)
                        {      gridclasspath.addItemAfter(new Object[]{txt},newItemId);                                
                        
                            txt.setEnabled(false);
                        }
                    });
                                            
                    
                }

My question is why i am able to add only the first item in the vaadin table.