Search in sources :

Example 1 with ClientCallable

use of com.vaadin.flow.component.ClientCallable in project flow by vaadin.

the class EventHandlerView method handleClientCall.

@ClientCallable
private String handleClientCall(String msg, boolean enabled) {
    if (!enabled) {
        throw new RuntimeException("Method is not enabled");
    }
    Element div = ElementFactory.createDiv("Call from client, message: " + msg + ", " + enabled);
    div.setAttribute("id", "client-call");
    getParent().get().getElement().appendChild(div);
    return msg.toUpperCase();
}
Also used : Element(com.vaadin.flow.dom.Element) ClientCallable(com.vaadin.flow.component.ClientCallable)

Example 2 with ClientCallable

use of com.vaadin.flow.component.ClientCallable in project flow by vaadin.

the class JavaScriptBootstrapUI method connectClient.

/**
 * Connect a client with the server side UI. This method is invoked each
 * time client router navigates to a server route.
 *
 * @param clientElementTag
 *            client side element tag
 * @param clientElementId
 *            client side element id
 * @param flowRoute
 *            flow route that should be attached to the client element
 * @param appShellTitle
 *            client side title of the application shell
 * @param historyState
 *            client side history state value
 */
@ClientCallable
@AllowInert
public void connectClient(String clientElementTag, String clientElementId, String flowRoute, String appShellTitle, JsonValue historyState) {
    if (getElement().getNode().isInert()) {
        // In inert state navigation is blocked, but client side callback
        // must be called.
        cancelClient();
        return;
    }
    if (appShellTitle != null && !appShellTitle.isEmpty()) {
        getInternals().setAppShellTitle(appShellTitle);
    }
    final String trimmedRoute = PathUtil.trimPath(flowRoute);
    if (!trimmedRoute.equals(flowRoute)) {
        // See InternalRedirectHandler invoked via Router.
        getPage().getHistory().replaceState(null, trimmedRoute);
    }
    final Location location = new Location(trimmedRoute);
    if (wrapperElement == null) {
        // Create flow reference for the client outlet element
        wrapperElement = new Element(clientElementTag);
        // Connect server with client
        getElement().getStateProvider().appendVirtualChild(getElement().getNode(), wrapperElement, NodeProperties.INJECT_BY_ID, clientElementId);
        getPage().getHistory().setHistoryStateChangeHandler(event -> renderViewForRoute(event.getLocation(), NavigationTrigger.CLIENT_SIDE));
        // Render the flow view that the user wants to navigate to.
        renderViewForRoute(location, NavigationTrigger.CLIENT_SIDE);
    } else {
        History.HistoryStateChangeHandler handler = getPage().getHistory().getHistoryStateChangeHandler();
        handler.onHistoryStateChange(new History.HistoryStateChangeEvent(getPage().getHistory(), historyState, location, NavigationTrigger.CLIENT_SIDE));
    }
    // true if the target is client-view and the push mode is disable
    if (getForwardToClientUrl() != null) {
        navigateToClient(getForwardToClientUrl());
        acknowledgeClient();
    } else if (isPostponed()) {
        cancelClient();
    } else {
        acknowledgeClient();
    }
    // If this call happens, there is a client-side routing, thus
    // it's needed to remove the flag that might be set in
    // IndexHtmlRequestHandler
    getSession().setAttribute(SERVER_ROUTING, Boolean.FALSE);
}
Also used : Element(com.vaadin.flow.dom.Element) HasElement(com.vaadin.flow.component.HasElement) History(com.vaadin.flow.component.page.History) Location(com.vaadin.flow.router.Location) ClientCallable(com.vaadin.flow.component.ClientCallable)

Example 3 with ClientCallable

use of com.vaadin.flow.component.ClientCallable in project flow by vaadin.

the class InjectScriptTagView method changeValue.

@ClientCallable
private void changeValue() {
    getModel().setValue("<!-- <SCRIPT>");
    getElement().removeAllChildren();
    Div slot = new Div(new Text("<!-- <SCRIPT> --><!-- <SCRIPT></SCRIPT>"));
    slot.setId("slot-2");
    getElement().appendChild(slot.getElement());
}
Also used : Div(com.vaadin.flow.component.html.Div) Text(com.vaadin.flow.component.Text) ClientCallable(com.vaadin.flow.component.ClientCallable)

Aggregations

ClientCallable (com.vaadin.flow.component.ClientCallable)3 Element (com.vaadin.flow.dom.Element)2 HasElement (com.vaadin.flow.component.HasElement)1 Text (com.vaadin.flow.component.Text)1 Div (com.vaadin.flow.component.html.Div)1 History (com.vaadin.flow.component.page.History)1 Location (com.vaadin.flow.router.Location)1