Skip to content

Commit

Permalink
Fix addComponentColumn not setting header caption #4
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuLund committed Jul 17, 2024
1 parent 854f9b7 commit 08c19f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
8 changes: 5 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.vaadin.tatu</groupId>
<artifactId>beantable</artifactId>
<version>3.1.5</version>
<version>3.1.6</version>
<name>BeanTable</name>
<description>Table component for Vaadin platform</description>
<properties>
<vaadin.version>24.2.2</vaadin.version>
<vaadin.version>24.3.3</vaadin.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jetty.version>11.0.14</jetty.version>
<jakarta.validation.version>3.0.2</jakarta.validation.version>
<hibernate.validator.version>8.0.1.Final</hibernate.validator.version>
</properties>
<organization>
<name>Tatu Lund</name>
Expand Down Expand Up @@ -104,7 +106,7 @@
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.4.1</version>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/vaadin/tatu/BeanTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ public Column<T> addComponentColumn(String header,
Objects.requireNonNull(componentProvider,
"A componentProvider must not be null");
Column<T> column = new Column<>();
column.setHeader(header);
column.setComponentProvider(componentProvider);
columns.add(column);
updateHeader();
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/org/vaadin/tatu/BeanTableTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.vaadin.tatu;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -200,6 +202,9 @@ public void beanTableWithComponents() {
ui.add(table);
fakeClientCommunication();

Assert.assertEquals("Name",
table.headerElement.getChild(0).getChild(1).getText());

AtomicInteger counter = new AtomicInteger(0);
table.bodyElement.getChildren().forEach(row -> {
int index = counter.getAndIncrement();
Expand Down Expand Up @@ -562,10 +567,21 @@ public void addThemeVariant_removeThemeVariant_themeNamesDoesNotContainThemeVari
}

@Test
public void tableSerializable() throws IOException {
public void tableSerializable() throws IOException, ClassNotFoundException {
BeanTable<String> table = new BeanTable<>();
table.addColumn("Hello", item -> "Hello");
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(table);
table.setItems("World");
var bs = new ByteArrayOutputStream();
var os = new ObjectOutputStream(bs);
os.writeObject(table);
os.flush();
os.close();

var a = bs.toByteArray();
ByteArrayInputStream bis = new ByteArrayInputStream(a);
ObjectInputStream in = new ObjectInputStream(bis);
var v = (BeanTable<String>) in.readObject();
Assert.assertEquals("World", v.getListDataView().getItem(0));
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/vaadin/tatu/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public Person(int id, String firstName, String lastName, int age,
this.age = age;
this.address = address;
this.phoneNumber = phoneNumber;
this.email = firstName + "." + lastName + "@" + "foo.org";
}

public Person(int id, String firstName, String lastName, int age,
Expand All @@ -41,6 +42,7 @@ public Person(int id, String firstName, String lastName, int age,
this.phoneNumber = phoneNumber;
this.maritalStatus = maritalStatus;
this.birthDate = birthDate;
this.email = firstName + "." + lastName + "@" + "foo.org";
}

public int getId() {
Expand Down

0 comments on commit 08c19f8

Please sign in to comment.