我是Vaadin的新手,但确实有一些Java Swing经验。
我正在尝试使用table.setCellStyleGenerator来设置标题为“Name”的特定单元格的颜色。
我正在使用vaadin书中的一个例子:
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);
我填写了表格如下:
/* 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));
我可以与我的样式表进行通信,但是当我尝试以下内容时:
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";
....
[b] PropertyId [/ b]显示为null。
并且Tomcat发出以下信息:
严重:终端错误:
java.lang.NumberFormatException:null
在java.lang.Integer.parseInt(未知来源)
我很确定我正在制作一些初学者错误。
顺便说一下,我的styles.css访问如下:
mainWindow.setTheme("colouredCells");
/* Create the table with a caption. */
Table table = new Table("Table with Cell Styles");
table.addStyleName("checkerboard");
并且CSS包含以下内容:
@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;
}
答案 0 :(得分:1)
null属性Id的原因在CellStyleGenerator的javadoc中进行了解释:还调用单元格样式生成器以选择性地为每一行设置样式,在该场景中,propertyId为null。如果propertyId为null,您可能只想返回null。