Table propertyId value is null when using setCellStyleGenerator

Hi,

Apologies as I am new to Vaadin but do have some Java Swing experience.

I am attempting to use table.setCellStyleGenerator to set the colour of a particular cell with the column heading “Name”.

I am working off an example in vaadin book:

Table table = new Table("Table with Cell Styles");
		table.addStyleName("checkerboard");

		table.addContainerProperty("0",String.class,null,"Name", null,  null);
		table.addContainerProperty("1",String.class,null,"Surname", null,  null);
		table.addContainerProperty("2",Date.class,null,"Date.", null,  null);
		table.addContainerProperty("3",Integer.class,null,"Required.", null,  null);
		table.addContainerProperty("4",Integer.class,null,"Complete", null,  null);
		
		
		table.addContainerProperty("5",String.class,null,"Cakes", null,  null);
		table.addContainerProperty("6",Integer.class,null,"Cake Quantity", null,  null);
		table.addContainerProperty("7",String.class,null,"Status", null,  null);
		table.addContainerProperty("8",TextField.class,null,"Notes", null,  null);

I have populated my table as follows:

/* Add a few items in the table. */
		table.addItem(new Object[] {
		    "Nicolaus","Copernicus",new Date("21/05/2011"), new Integer(1473), new Integer(1), "Cake",  new Integer(1473), "cakestatus", commentsField }, new Integer(3));

I am able to communicate with my stylesheet but when I try the following:

table.setCellStyleGenerator(new Table.CellStyleGenerator() {
		    public String getStyle(Object itemId, Object propertyId) {
		        int row = ((Integer)itemId).intValue();
		      int col = Integer.parseInt((String)propertyId);
		       
		       
		     System.out.println("COL:"+ col);  
		        // The first column.
		      if (col == 0)
		         return "rowheader";
                                      ....


PropertyId
appears null.

and Tomcat spews the following:

I’m pretty sure I’m making some beginners error.

Btw my styles.css is accessed as follows:

mainWindow.setTheme("colouredCells");
		
	/* Create the table with a caption. */
	Table table = new Table("Table with Cell Styles");
	table.addStyleName("checkerboard");

and the CSS contains the following:

 @import url(../colouredCells/styles.css);
/* Using the old default theme (runo) as the basis for now */





/* Center the text in header. */
.v-table-header-cell {
    text-align: center;
}

/* Basic style for all cells. */
.v-table-checkerboard .v-table-cell-content {
    text-align: center;
    vertical-align: middle;
    padding-top: 12px;
    width: 20px;
    height: 28px;
}

/* Style specifically for the row header cells. */
.v-table-cell-content-rowheader {
	background: #E7EDF3
     url(../default/table/img/header-bg.png) repeat-x scroll 0 0;
}

/* Style specifically for the "white" cells. */
.v-table-cell-content-white {
    background: white;
    color: black;
}

/* Style specifically for the "black" cells. */
.v-table-cell-content-black {
    background: #60497b;
    color: white;
}

Hi Roger,


javadoc for CellStyleGenerator
The reason for the null propertyId is explained in the : the cell style generator is also called to optionally set a style for each row, and in that scenario, the propertyId is null. You’ll probably want to simply return null if the propertyId is null.

Hope that helps!

Charles.