Hi Hristo,

This mailing list isn't allowing attachments, we cannot see it, so it's a
bit unclear what you need.

> How could I possibly make an event listener inside Java?

What events should the listener listen to, is it a client-side or
server-side event?

To call Java methods from JS you usually build an API endpoint, i.e. with
Resteasy or GraphQL.
I presume you'll need access to the Tapestry context, you can use on of the
ready-to-use integrations,
e.g. http://www.tynamo.org/tapestry-resteasy+guide/

Alternatively, if you need to call a Tapestry page/component and
potentially render some markup in response
you can generate an event link from the page/component and pass it to JS
via the initialiser, for example, in your page/component class:

    @Inject ComponentResources componentResources;

    public void afterRender()
    {
        JSONObject json = new JSONObject()

.put("myEventURL",
componentResources.createEventLink("myEvent").toRedirectURI());

        // this will invoke a client-side function with arguments
        javaScriptSupport.require("myJSModule").invoke("myInit").with(json);
    }

    @OnEvent("myEvent")
    public void onMyEvent() {
        // TODO Handle event on the server-side
    }

and then create META-INF/modules/myJSModule.js and put the following code
to receive the call on client-side:

(function () {

    // you can define module dependencies if you need them
    define(["t5/core/ajax"], function (ajax) {

        function init(spec) {
            // read argument here, and when needed use the URL to call it
with `ajax`
            alert(spec.myEventURL);
        }

        return {
            init: init
        };
    });
})();




On Fri, Oct 9, 2020 at 8:51 AM Hristo Stoyanov <aironhi...@yahoo.com.invalid>
wrote:

> Hello everyone!
>
> I have been brought onboard to an Tapestry project(never heard of it
> before) and I would like to create a 'communication channel' between the
> tapestry and an iframe(displaying Angular application).
>
> Both projects are on the same domain and the Angular app inside the iframe
> works as expected, but I would like to send data to the Angular project and
> vice versa.
>
> I found out that you can communicate between parent window and iframe by
> using cross-document messaging (
> https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage)
>
> My question is:
> How could I possibly make an event listener inside Java? The javascript
> for doing so should look something like this
> "window.document.addEventListener("myEvent", 'JS function to handle',
> false);"
> And also how to actually call a method inside Java from the JavaScript
> code.
>
> I asked here and there and nobody was able to help me with that so far...
> I will be very thankful if you can help me with that.
>
> There is a small image that can helpfully help you understand my idea:
> [image: Inline image]
>
> Thank you in advance!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Reply via email to