【问题标题】:Download component in Vaadin grid with Kotlin使用 Kotlin 在 Vaadin 网格中下载组件
【发布时间】:2022-01-01 03:56:22
【问题描述】:

我想使用 Kotlin 和 Vaadin 14 在网格中提供下载按钮:

grid.addComponentColumn{item ->
    val button = Button(item.plandatei)
    val resource = StreamResource(item.plandatei) { this.getStream(item.plandatei) }
    val anchor = Anchor(resource)
    anchor.getElement().setAttribute("download", true)
    anchor.getElement().appendChild(button.getElement())
    return@addComponentColumn anchor
}


fun getStream(filename: String): InputStream {
    val file = File(filename)
    file.readBytes()
}

我收到此错误消息:

Overload resolution ambiguity. All these functions match.
public constructor StreamResource(name: String!, factory: InputStreamFactory!) defined in 
com.vaadin.flow.server.StreamResource
public constructor StreamResource(name: String!, writer: StreamResourceWriter!) defined in 
com.vaadin.flow.server.StreamResource

如何将 getStream 函数中的 InputStream 转换为 InputStreamFactory?还是别的什么?

【问题讨论】:

    标签: kotlin vaadin-flow vaadin-grid vaadin14


    【解决方案1】:

    您需要帮助 Kotlin 编译器。请尝试

    val resource = StreamResource(item.plandatei, InputStreamFactory { this.getStream(item.plandatei) } )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-26
      • 1970-01-01
      • 2019-07-13
      • 2013-06-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多