Java Vaadin 14在“新浏览器”选项卡中打开新零部件

Java Vaadin 14在“新浏览器”选项卡中打开新零部件,java,pdf,vaadin,vaadin14,Java,Pdf,Vaadin,Vaadin14,有没有办法打开嵌入到组件中的pdf并发送到新的浏览器选项卡 其思想是将资源设置为此组件,并在新选项卡中打开。我以后需要在更多的按钮中导航不同的文档 在Vaadin.com论坛上讨论您的问题 Anchor::setTarget➙ “\u blank” 将小部件用于链接。看 ➥ 关键是将“目标”设置为字符串\u blank String url = "…" ; Anchor anchor = new Anchor( url , "Open a PDF document" ) ; anchor.se

有没有办法打开嵌入到组件中的pdf并发送到新的浏览器选项卡

其思想是将资源设置为此组件,并在新选项卡中打开。我以后需要在更多的按钮中导航不同的文档

在Vaadin.com论坛上讨论您的问题

Anchor::setTarget
➙ <代码>“\u blank” 将小部件用于链接。看

➥ 关键是将“目标”设置为字符串
\u blank

String url = "…" ;
Anchor anchor = new Anchor( url , "Open a PDF document" ) ;
anchor.setTarget( "_blank" ) ;  // Specify `_blank` to open in a new browser tab/window.
下面是Vaadin14.1.19中的一个完整示例应用程序,它基于
普通Javaservlet的一个变种

运行此示例应用程序。单击该链接可看到另一个web浏览器选项卡打开并显示PDF文档

package work.basil.example;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;

/**
 * The main view contains a button and a click listener.
 */
@Route ( "" )
// @PWA ( name = "Project Base for Vaadin", shortName = "Project Base" )
@CssImport ( "./styles/shared-styles.css" )
@CssImport ( value = "./styles/vaadin-text-field-styles.css", themeFor = "vaadin-text-field" )
public class MainView extends VerticalLayout
{

    public MainView ( )
    {
        // Widgets
        H1 heading = new H1( "Download PDF in browser tab" );

        String url = "https://www.fda.gov/media/76797/download";
        Anchor anchor = new Anchor( url , "Open a PDF document" );
        anchor.setTarget( "_blank" );  // Specify `_blank` to open in a new browser tab/window.

        // Arrange
        this.add( heading , anchor );
    }
}

您好,抱歉,我添加了一个图像以使其更清晰。我想知道我们是否可以设计一个组件,它有一个带有pdf embded的工具栏,并发送到一个新的选项卡,供用户浏览和阅读不同的pdf?你的问题越来越不清楚了。我怀疑你真的在问什么应该是两个独立的问题帖子。我想我会尝试你在另一个问题上提到的方法。我将构建一个UI并通过参数加载它们。
package work.basil.example;

import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.PWA;

/**
 * The main view contains a button and a click listener.
 */
@Route ( "" )
// @PWA ( name = "Project Base for Vaadin", shortName = "Project Base" )
@CssImport ( "./styles/shared-styles.css" )
@CssImport ( value = "./styles/vaadin-text-field-styles.css", themeFor = "vaadin-text-field" )
public class MainView extends VerticalLayout
{

    public MainView ( )
    {
        // Widgets
        H1 heading = new H1( "Download PDF in browser tab" );

        String url = "https://www.fda.gov/media/76797/download";
        Anchor anchor = new Anchor( url , "Open a PDF document" );
        anchor.setTarget( "_blank" );  // Specify `_blank` to open in a new browser tab/window.

        // Arrange
        this.add( heading , anchor );
    }
}