Database connection from Client screen / Service

Hi everyone.
I need to create a report only if a user clicks a button on a screen.
Is there a way to get a connection to the database from a Screen Controller? Or the way is create a service that creates the report on the given input and return it to the controller?

Hi Federico,

the latter one is correct. You just define a service that gets executed in the middleware block (core module). In the controller you’ll just inject the service and call the corresponding method.

An example of this you’ll find here:

  • [url=https://github.com/mariodavid/cuba-ordermanagement/blob/master/modules/core/src/com/company/ordermanagement/service/DeepLinkServiceBean.groovy]DeepLinkServiceBean[/url] (core module)
  • [url=https://github.com/mariodavid/cuba-ordermanagement/blob/master/modules/global/src/com/company/ordermanagement/service/DeepLinkService.java]DeepLinkService Interface[/url] (global module)
  • [url=https://github.com/mariodavid/cuba-ordermanagement/blob/a11401554e03d56fef88b3fb7f640cdf444b10a4/modules/gui/src/com/company/ordermanagement/gui/customer/CustomerBrowse.java]Controller that uses the service[/url] (gui module)
As you see [url=https://github.com/mariodavid/cuba-ordermanagement/blob/a11401554e03d56fef88b3fb7f640cdf444b10a4/modules/gui/src/com/company/ordermanagement/gui/customer/CustomerBrowse.java#L32]here[/url] you can pass parameters from the controller and get results back.

Are you talking about the report facility from CUBA? In this case, you should have a look at this section in the docs on how to run a report from a screen.

You can also work with data on the client tier through DataManager, as in this example.