Call a REST service through a buttonClick

Good Morning,

I need help to perform some tests. It turns out that in Eclipse I have two calls to REST services that return data of type String. What I intend to do is have a screen with a button and a TextArea, and at the moment click on the button, said TextArea is filled with the data it collects from the call.

Everything works perfectly in Eclipse, but I do not know how to take it inside CUBA Studio, can someone help me?

Thank you very much,
Greetings.

Hello, @jordi.gisbert.ponsoda!

I prepared a simple example that could help you.

1 Like

Good morning,

Thank you very much for the example, I am already investigating and seeing how it works. The thing is that I copied the code you have in the controller, and I paste it in my controller, inside CUBA, with the aim of seeing what it does, modifying and learning. However, when I click on apply, it tells me that the code has been saved, but when I close and open the controller again I see that the code has been completely deleted, it is not saved in CUBA Studio, you know what it is ?

Thank you very much,
Greetings.

Do you use CUBA Studio with Eclipse IDE?

Yes, but when I click IDE to go to Eclipse and see the code, there are empty.

Greetings.

Please try to save the code in Eclipse (and reopen the screen in Studio).

Good afternoon,

I have already managed to see the code in both Eclipse and Cuba and change instantly. I have copied your code and changed to a Token class that I have created, where are the parameters “access_token” and other that the call returns. However, when I execute in CUBA I get an error and just in that class and in the package. “error: package x.xx.xxx.modelo does not exist”, and the other errors are of the Token class created by me. How can I import it? If it is assumed that in Eclipse everything works perfectly and I receive the necessary token.

Thank you very much,
Greetings.

Where is Token class? It must be in global module or web. Not in core - core is invisible to web.

1 Like

Hello,

Yes, I have the Token class in the core module, I’m going to change the class to the web module and test it again.

Thanks,
Regards.

Good afternoon,

Thank you very much, that was my fault, I had everything in the CORE module, and it turns out that it had to be put in the WEB module. Is there any difference between putting it in the WEB module or the GLOBAL module?

Thank you very much again,
Greetings.

Hello, @jordi.gisbert.ponsoda!

I’m glad that everything is works.

Classes from global module will be seen in all modules.
Classes from web module will be seen only in web.

I use rest service on this report.