Search in sources :

Example 1 with IFrame

use of com.vaadin.flow.component.html.IFrame in project flow by vaadin.

the class PageView method beforeEnter.

@Override
public void beforeEnter(BeforeEnterEvent event) {
    Input input = new Input();
    input.setId("input");
    input.clear();
    Div updateButton = new Div();
    updateButton.setId("button");
    updateButton.setText("Update page title");
    updateButton.addClickListener(e -> {
        getPage().setTitle(input.getValue());
    });
    Div overrideButton = new Div();
    overrideButton.setId("override");
    overrideButton.setText("Triggers two updates");
    overrideButton.addClickListener(e -> {
        getPage().setTitle(input.getValue());
        getPage().setTitle("OVERRIDDEN");
    });
    Div reloadButton = new Div();
    reloadButton.setId("reload");
    reloadButton.setText("Reloads the page");
    reloadButton.addClickListener(e -> {
        getPage().reload();
    });
    VaadinServletRequest request = (VaadinServletRequest) VaadinRequest.getCurrent();
    HttpServletRequest httpServletRequest = request.getHttpServletRequest();
    String url = httpServletRequest.getRequestURI().replace(PageView.class.getName(), BaseHrefView.class.getName());
    Div setLocationButton = new Div();
    setLocationButton.setId("setLocation");
    setLocationButton.setText("Set page location");
    setLocationButton.addClickListener(e -> getPage().setLocation(url));
    Div openButton = new Div();
    openButton.setId("open");
    openButton.setText("Open url in a new tab");
    openButton.addClickListener(e -> getPage().open(url));
    IFrame frame = new IFrame();
    frame.setId("newWindow");
    frame.setName("newWindow");
    Div openButton2 = new Div();
    openButton2.setId("openInIFrame");
    openButton2.setText("Open url in an IFrame");
    openButton2.addClickListener(e -> getPage().open(url, "newWindow"));
    add(input, updateButton, overrideButton, reloadButton, setLocationButton, openButton, openButton2, frame);
    add(new NativeButton("page.fetchURL", onClickEvent -> {
        getUI().ifPresent(ui -> ui.getPage().fetchCurrentURL(currentUrl -> {
            LoggerFactory.getLogger(PageView.class.getName()).info(currentUrl.toString());
        }));
    }));
}
Also used : Div(com.vaadin.flow.component.html.Div) HttpServletRequest(javax.servlet.http.HttpServletRequest) Input(com.vaadin.flow.component.html.Input) HttpServletRequest(javax.servlet.http.HttpServletRequest) BeforeEnterEvent(com.vaadin.flow.router.BeforeEnterEvent) IFrame(com.vaadin.flow.component.html.IFrame) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest) LoggerFactory(org.slf4j.LoggerFactory) Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) VaadinRequest(com.vaadin.flow.server.VaadinRequest) ViewTestLayout(com.vaadin.flow.uitest.servlet.ViewTestLayout) Route(com.vaadin.flow.router.Route) NativeButton(com.vaadin.flow.component.html.NativeButton) Input(com.vaadin.flow.component.html.Input) IFrame(com.vaadin.flow.component.html.IFrame) VaadinServletRequest(com.vaadin.flow.server.VaadinServletRequest)

Aggregations

Div (com.vaadin.flow.component.html.Div)1 IFrame (com.vaadin.flow.component.html.IFrame)1 Input (com.vaadin.flow.component.html.Input)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 BeforeEnterEvent (com.vaadin.flow.router.BeforeEnterEvent)1 Route (com.vaadin.flow.router.Route)1 VaadinRequest (com.vaadin.flow.server.VaadinRequest)1 VaadinServletRequest (com.vaadin.flow.server.VaadinServletRequest)1 ViewTestLayout (com.vaadin.flow.uitest.servlet.ViewTestLayout)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LoggerFactory (org.slf4j.LoggerFactory)1