Downloaded filename (including its extension) is not respected in Vaadin Portlet when running in Liferay 7.
The following code aims to add a download button with excel file download action:
public class ContactListView extends VerticalLayout implements PortletView {
private Collection<StreamRegistration> streamRegistrations;
@Override
public void onPortletViewContextInit(PortletViewContext context) {
add(download());
}
@Override
protected void onDetach(DetachEvent detachEvent) {
if (streamRegistrations != null) {
streamRegistrations.forEach(StreamRegistration::unregister);
streamRegistrations.clear();
}
super.onDetach(detachEvent);
}
private Button download() {
return new Button("Download File", click -> {
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream("Book1.xlsx");
StreamResource downloadResource = new StreamResource("export.xlsx", () -> resourceAsStream);
downloadResource.setContentType("application/xls");
downloadResource.setHeader("Content-Disposition",
"attachment;filename=export.xlsx");
final StreamRegistration registration =
VaadinPortletSession.getCurrent().getResourceRegistry().registerResource(downloadResource);
UI.getCurrent().getPage().open(registration.getResourceUri().toString());
if (streamRegistrations == null) {
streamRegistrations = new LinkedList<>();
}
streamRegistrations.add(registration);
});
}
}
Versions:
Vaadin Portlet version - 1.0.0.beta4
Vaadin Platform version - 14.8.3
Liferay version - 7.3
Java version - 11
OS version - Windows 10
Browser version (if applicable) - Chrome 96
Downloaded filename (including its extension) is not respected in Vaadin Portlet when running in Liferay 7. The following code aims to add a download button with excel file download action:
Expected the filename is "export.xlsx", but actual filename is "home". Request URL = http://localhost:8080/web/guest/home?p_p_id=ContactList_WAR_addressbookgrid&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_resource_id=/uidl&p_p_cacheability=cacheLevelPage&v-r=uidl&v-uiId=0
Minimal reproducible example: Use https://github.com/vaadin/addressbook-portlet/tree/feature/liferay starter and add the above code.
Versions: Vaadin Portlet version - 1.0.0.beta4 Vaadin Platform version - 14.8.3 Liferay version - 7.3 Java version - 11 OS version - Windows 10 Browser version (if applicable) - Chrome 96