Vaadin 8 Grid getColumn returns null

Hi all,

I’m trying to set up a simple Grid in my app (Vaadin 8.1.0) and configure it. But i seem to miss something and I just don’t see, where the issue is. The problem, I encounter is, that the getColumn() method on the grid returns null. The grid shows up and displays the data I want it to display. So, that part works. Now I just wanted to add a filter using a Texfield in the column header. Heres the code snippet, that causes the error:

List b = Buchungen.findAll();
Grid gb = new Grid<>();
gb.setItems(b);
gb.addColumn(Buchungen::getBuchungstag).setCaption(“Buchungsdatum”); gb.addColumn(Buchungen::getTarget).setCaption(“Target”);

Object o = gb.getColumn(“target”); //<— this line returns null (just test code)

My entity class looks like this:

public class Buchungen {

private Date buchungstag;
private String target;

@Basic
@Column(name = “target”)
public String getTarget() { return target; }

Looks to me quite simple but somehow, I miss something essential. Does anyone have a hint for me how to fix this issue?
Thanks for any advice in advance!
Cheers,
Jörg

Hi,

where’s the @Column annotation coming from?

-Olli

Hi Olli,

thanks for your reply. The @Column annotation is from the java.persisence package and belongs to my entity class. By the way: If I call Grid.getColulmns() I get a Lisgt of all columns back - just without an ID. In fact, I don’t seen any “columnID” field in my debugger (IDEA). Just numbers (“0”,“1”). Any idea?

Cheers,
Joerg

Hi,

since you are using the addColumn with a ValueProvider (addColumn with a method reference) instead of a property name (addColumn with String parameter), you end up just giving the column a generated id. See here: https://github.com/vaadin/framework/blob/master/server/src/main/java/com/vaadin/ui/Grid.java#L2651 - the “0” and “1” are the generated identifiers. You could do something like this instead:

Grid.Column<xx, xx> targetColumn = gb.addColumn(Buchungen::getTarget).setCaption("Target");
targetColumn.doSomething(); // instead of gb.getColumn("target")

-Olli

Hi again,

thanks a lot for youe help! That really did the trick! I missed, thatg I get a return value from the addColumn method…:(… But now everything works as it should! Thanks again for your help!

Cheers,
Joerg

That’s something to keep an eye out for - methods that can take Lambda parameters usually return an object, since lambdas are ephemeral. For example, add*Listener methods return Registration objects in Vaadin 8.

-Olli