2011-05-31 2 views
0

Je suis un nouveau venu chez Vaadin, mais je possède une certaine expérience Java Swing.La valeur de la propriété propertyId du tableau est null lors de l'utilisation de setCellStyleGenerator

J'essaie d'utiliser table.setCellStyleGenerator pour définir la couleur d'une cellule particulière avec l'en-tête de colonne "Nom".

Je travaille au large un exemple dans le livre de 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); 

J'ai rempli ma table comme suit:

/* 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)); 

Je suis en mesure de communiquer avec ma feuille de style, mais quand je effectuez les opérations suivantes :

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] L'ID de propriété [/ b] apparaît null.

et Tomcat SPEWS les éléments suivants:

SEVERE: Terminal error:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)

Je suis sûr que je fais une erreur de débutants.

Btw mon styles.css est accessible comme suit:

mainWindow.setTheme("colouredCells"); 

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

et le CSS contient les éléments suivants:

@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

Sans regarder correctement autre chose, au moins la règle d'importation CSS pointe vers une URL incorrecte: je suppose que vous voulez étendre à partir de Runo ou Reindeer, il devrait donc dire @import url (../ styles/runo/styles.css); Et vous devez également spécifier le thème à l'application, pas à la mainWindow (bien que je pense que cela ne fait aucune différence), c'est juste comment c'est généralement fait. – Jouni

Répondre

1

La raison de l'hypothèse nulle PropertyId est expliqué dans le javadoc pour CellStyleGenerator: la Le générateur de style de cellule est également appelé pour définir éventuellement un style pour chaque ligne, et dans ce scénario, l'attribut propertyId est null. Vous voudrez probablement simplement retourner null si l'attribut propertyId est null.

Questions connexes