How to call a method in the action of a button? Help please

Good Morning,

I explain my case to see if someone can help me. It turns out that I have some methods in Java (Eclipse) with which I call a REST service and I get certain data that I need to show on the screen. But my problem is that I do not know how to make the button I have on my screen call that method, that is, I can not integrate the code I have in Eclipse with a CUBA action.

Can anybody help me?

Thank you very much,
Greetings.

Hi.

You can define a controller method that should be invoked after a click on a button using invoke attribute. The attribute value should contain name of the controller method satisfying the following conditions:

  • The method should be public.

  • The method should return void.

  • The method should not have any arguments or should have a single argument of Component type. If the method has a Component argument, then an instance of the invoking button will be passed in it.

Below is the example of a button invoking someMethod:

<button invoke="someMethod" caption="msg://someButton"/>

1 Like

Hello Natalia,

I have not understood very well what you have told me in the post that I indicate here above. I explain to you with something more depth: I have a method with which I call a REST service, this method returns a kind of “TOKEN for a LOGIN”. So what I want to do in CUBA, is to press a button and fill in a text field with that generated token.

The truth. I’m pretty lost and I do not know how to integrate this code.

Thank you very much,
Greetings.

Look at this example please: Business Logic in Controllers. It shows how to define an action and button in XML descriptor and a controller method that is invoked by this action.