Calling java from html

Hi. I have html templates generated on server side and then shown inside Vaadin div element. Is it possible to open Vaadin dialog from native html href? Or calling Java function from native javascript /html?

See @ClientCallable

Is there any example. I can not get it to work.

I ve seen this of course.

https://github.com/vaadin/flow/blob/master/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/template/JsInjectedDiv.java

Should something like this work.
Vaadin div content it’s populated like this:

`div.getElement()
            .setProperty("innerHTML", myHtmlTemplateString);

`

`
String myHtmlTemplateString = “”"

My trendered Apache freemark Template

Click me
“”"

`

Depends what’s inside callVaadinServerFunction

What should be😀

I would like to open Dialog from server side.

this.$server won’t work because it’s not known to the server… I’m not sure if server is also available on document or window. But looking at your code it’s probably easier to replace the whole button with a real Vaadin button from the server side by e.g. injecting it with something like https://cookbook.vaadin.com/custom-layout

Thanks @quirky-zebra . It’s working as expected.

Are there any performance issues with this approach?

I would argue it’s even faster :sweat_smile: but in reality you won’t notice

@quintessential-ibex also created a custom layout variant for viritin (still hoping for an official component :sweat_smile:)

I am now using Matti’s custom layout. It was created exactly for my needs :).

References in my pure html generated with Apache freemarker templates are now clickable with native Vaadin button. This really is great. PDF’s are generated from this templates with no problem.
Thanks @quirky-zebra

:+1: Glad to see my contribution helping you :sunglasses:

Freemarker is great for that kind of stuff. I helped Alejandro to hack together this post & add-on couple of years ago: Dynamic HTML templates with FreeMarker and Vaadin | Vaadin