Search code examples
javascriptspringvaadinclient-serverillegalargumentexception

How can I change Vaadin Components in Java through Javascript


I implemented Shepherd in my Vaadin Project, so i can guide users in tours through my web application. But, i need to get access from the javascript on the Accordion Components in Vaadin, to open or close specific tabs. For this, i need to have access on the open() and close() method for the Accordion Components. So how can i access them through Javascript?

Already seen the Tutorial on the Website of them: Vaadin calling java from javascript, but sadly nothing over there, what could help me. I already tried to use something like this:

UI.getCurrent().getPage().executeJs("window.startTour($0, $1)", this, Accordion1.getElement());

But when i try to bind it in javascript through:

window.startTour = (element, accordion) => { ... }

and in this window:

beforeShowPromise: function () {
    return new Promise(function(resolve) {
    element.$server.openAccordion(accordion.$server, 1);
    resolve();
    });
},

with the following method in java:

@SuppressWarnings("unused")
@ClientCallable
public void openAccordion(Object object, int index) {
        Accordion accordion = (Accordion) object.get(this);
    accordion.open(index);
}

i only get the following error message:

Class '...' has the method 'openAccordion' whose parameter 0 refers to unsupported type 'java.lang.Object'

No matter what i use as first parameter, everythin that extends Object doesnt work and i dont know why.

I found a recent post with the same question, but it was not helpful for me: Unable to send a new bean instance to the server

Im using Intellij and in my Project: Java, Spring, Vaadin and Shepherd

Already tried to use different parameters, but only the int parameter is working, Object doesnt work. The Problem is, i cant change the opened Tab of the Accordion from the Javascript over the Java, because of this error, so i have to implement for each Accordion 2 methods to open and close it.

Maybe somebody can help me with it or knows some tricks to master this. Thanks


Solution

  • When using @ClientCallable you can pass only json or primitive types from JavaScript call to server. There is a real systems boundary here. Object is not supported and furthermore, you can cast that parameter to Java object.