Download 下载时文件名默认为Vaadin Flow app中用户事件的日期时间

Download 下载时文件名默认为Vaadin Flow app中用户事件的日期时间,download,vaadin,vaadin-flow,Download,Vaadin,Vaadin Flow,在我的web应用程序版本14或更高版本中,我希望向我的用户提供一个链接,该链接将向他们下载数据文件。要下载的文件的默认名称应在用户启动下载时确定 String when = Instant.now().toString().replace( "-" , "" ).replace( ":" , "" ); // Use "basic" version of standard ISO 8601 format for date-time. StreamResource streamResource =

在我的web应用程序版本14或更高版本中,我希望向我的用户提供一个链接,该链接将向他们下载数据文件。要下载的文件的默认名称应在用户启动下载时确定

String when = Instant.now().toString().replace( "-" , "" ).replace( ":" , "" ); // Use "basic" version of standard ISO 8601 format for date-time.
StreamResource streamResource = new StreamResource( "rows_" + when + ".txt" , ( ) -> this.makeContent() );
Anchor anchor = new Anchor( streamResource , "Download generated data" );
我知道Vaadin Flow中的小部件。对于锚,下载文件的默认名称将是链接URL中给定的资源名称。不幸的是,这是在页面加载时确定的,而不是稍后用户单击链接时确定的。因此,这种方法无法满足我的需要,即用用户启动下载时捕获的日期和时间来标记下载

String when = Instant.now().toString().replace( "-" , "" ).replace( ":" , "" ); // Use "basic" version of standard ISO 8601 format for date-time.
StreamResource streamResource = new StreamResource( "rows_" + when + ".txt" , ( ) -> this.makeContent() );
Anchor anchor = new Anchor( streamResource , "Download generated data" );
也许解决方案是使用按钮小部件而不是锚。使用动态创建内容的按钮显示在手册的“高级主题”>“页面”中。不幸的是,这里的示例在页面上加载资源,而不是为用户下载

➥ 可以使用Vaadin Flow中的按钮启动下载吗

➥ 是否有其他方法在用户启动下载时而不是页面加载时确定URL来启动下载

可以使用Vaadin Flow中的按钮启动下载吗

是的,但它需要一些客户端实现。目录中有一个加载项,它可以执行此操作。使用,可以包裹例如按钮。但我认为这并不能完全解决你们的问题。我怀疑click事件中的文件名设置不会应用,因为太晚了。但我确实认为,可以将文件名提供程序回调功能添加到这个插件中

可以使用Vaadin Flow中的按钮启动下载吗


是的,但它需要一些客户端实现。目录中有一个加载项,它可以执行此操作。使用,可以包裹例如按钮。但我认为这并不能完全解决你们的问题。我怀疑click事件中的文件名设置不会应用,因为太晚了。但我确实认为,将文件名提供程序回调功能添加到此加载项是可能的。

考虑一下这种模拟点击客户端上动态添加的锚的黑客行为:

私有void下载解决方案组件anyComponent,int delay{ Anchor hiddenDownloadLink=新AnchorcreateStreamResource,解决方案; hiddenDownloadLink.SetIdeExportLinkWorkAround+System.currentTimeMillis; hiddenDownloadLink.getElement.setAttributestyle,显示:无; var parent=anyComponent.getParent.orelsetrow; var parenthc=HasComponents父项; 对于组件c:parent.getChildren.collectCollectors.toList{ 如果c.getId.orElse.StartWithExportLink解决方案{ //清理旧的下载链接 parenthc.removec; } } parenthc.addhiddenDownloadLink; UI.getCurrent.getPage.ExecuteJSettimeoutFunction{+//delay作为之前打开对话框时的错误解决方法 document.getElementById'+hiddenDownloadLink.getId.orElseThrow+'。单击; +},+延迟+; ; } 在按钮单击事件或其他事件上调用方法。有时需要额外的延迟。对我来说,从模式对话框OK按钮开始下载时需要延迟,该按钮也关闭了对话框。但也许你根本不需要这个


对于Tatu针对我的特定用例提到的文件下载包装插件,我运气不佳:在向用户提供下载之前,我想在某些情况下显示一个对话框。

考虑一下这种模拟点击客户端上动态添加的锚的黑客行为:

私有void下载解决方案组件anyComponent,int delay{ Anchor hiddenDownloadLink=新AnchorcreateStreamResource,解决方案; hiddenDownloadLink.SetIdeExportLinkWorkAround+System.currentTimeMillis; hiddenDownloadLink.getElement.setAttributestyle,显示:无; var parent=anyComponent.getParent.orelsetrow; var parenthc=HasComponents父项; 对于组件c:parent.getChildren.collectCollectors.toList{ 如果c.getId.orElse.StartWithExportLink解决方案{ //清理旧的下载链接 parenthc.removec; } } parenthc.addhiddenDownloadLink; UI.getCurrent.getPage.ExecuteJSettimeoutFunction{+//delay作为之前打开对话框时的错误解决方法 document.getElementById'+hiddenDownloadLink.getId.orElseThrow+'。单击; +},+延迟+; ; } 在按钮单击事件或其他事件上调用方法。有时需要额外的延迟。对我来说,从模式对话框OK按钮开始下载时需要延迟,该按钮也关闭了对话框。但也许你根本不需要这个

我在下载wrapp文件时运气不好 Tatu在我的特定用例中提到的er插件:在向用户提供下载之前,我想在某些情况下显示一个对话框