Litrenderer in grid when column value is null

I have a grid with a column rendered with a litrenderer. This column gets its value from another related entity by one2one relationship an it is nullable. I want the renderer to only work when value is not null, but I don’t know how to afford this. I’m learning vaadin and I’ve read the docs but I haven’t found the way. Basically I followed the steps in vaadin grid component docs using litrender.

Thank you

You need to deal with the null value in the renderer.

Finally I use this code private static Renderer<Copy> createStudentRenderer() { return LitRenderer.<Copy>of( "<vaadin-horizontal-layout ?hidden=\"${item.hidden}\" style=\"align-items: center;\" theme=\"spacing\">" + "<vaadin-avatar img=\"${item.pictureUrl}\" name=\"${item.fullName}\" alt=\"User avatar\"></vaadin-avatar>" + " <vaadin-vertical-layout style=\"line-height: var(--lumo-line-height-m);\">" + " <span> ${item.fullName} </span>" + " <span style=\"font-size: var(--lumo-font-size-xxs); color: var(--lumo-secondary-text-color);\">" + " ${}" + " </span>" + " </vaadin-vertical-layout>" + "</vaadin-horizontal-layout>") .withProperty("hidden", copy -> copy.getBorrow() == null ? true : false) .withProperty("pictureUrl", copy -> copy.getBorrow().getStudent().getPerson().getPhotoBase64()) .withProperty("fullName", copy -> copy.getBorrow().getStudent().getPerson().getLastName() + ", " + copy.getBorrow().getStudent().getPerson().getFirstName()) .withProperty("date", copy -> copy.getBorrow().getBorrowDate().atZone(ZoneId.systemDefault()) .toLocalDateTime().format(DateTimeFormatter.ofPattern(DATEFORMAT))); }but I think this is a hard way to achieve this behaviour

You don’t have a nullpointerexception if copy.getBorrow() is null?

Sorry about that, this code is wrong, in the “good” renderer I check all properties, with a ternary operator, if copy.getBorrow() is null, and in that case returns “”. I use the hidden property to not render if is null. I think there would be an easier way to do this.

If the copy object is an entity that loads eagerly a student+ person + borrow then the performance is usually pretty bad. You can use a dto and get the data you need.

All objects are lazily loaded, I use a customized query join fetch in repo to get data needed.