Hi All,
Fairly new to Vaadin (+ Viritin) but I’m already loving the framework! I’ve never much enjoyed UI work so it’s really refreshing to find something that gives me the power to create good looking modern web UIs without all the fuss.
My current project uses Viritin ElementCollectionField to show a (non-editable) list, and in each row I need to have a Vaadin Link to an ExternalResource, with an image that also comes from an ExternalResource (another servlet in the same webapp). The List is “documents” that are attached to another entity (via a JPA ManyToMany).
My Row class for the ElementCollectionField looks like this:
[code]
public static class DocumentRow {
public MTextField id = new MTextField();
public MTextField name = new MTextField();
public MTextField description = new MTextField();
public Link iconLink;
MButton download = new MButton(FontAwesome.DOWNLOAD, e -> {
Page.getCurrent().open(new ExternalResource(Document.getDownloadURL(id.getValue())), "_blank", false);
});
}
[/code]I wasn’t sure how I should set the properties on the iconLink object, which need to be set according to properties of the entity the row is displaying. My current approach has been to modify AbstractElementCollection, so that I can use an editor instantiator that receives the entity the row is being created for. With this modification, I create the ElementCollectionField like so:
[code]
private final ElementCollectionField attachedDocuments = new ElementCollectionField(
Document.class,
DocumentRow.class
)
.withFullWidth()
.withVisibleHeaders(false)
.withNewEditorInstantiator((doc) → {
DocumentRow row = new DocumentRow();
row.iconLink = new Link("", new ExternalResource(doc.getDownloadURL()));
row.iconLink.setIcon(new ExternalResource(doc.getIconURL()));
return row;
}
);
[/code](withNewEditorInstantiator is just a method I added to ElementCollectionField to expose the functionality I added to AbstractElementCollection, and the Document class is a simple JPA entity).
This seems to work fine - my links are set up properly and the images display without problem. But I’m wondering if there’s something I’ve missed? Is there a better way to achieve what I want with the existing Viritin code?
Thanks in advance,
Ross