Newbie Question: Place a method and call it with a Browser button

Hey All,

I have a method that I’ve written in Java, which houses a database query and creates a file that will be placed in s3.

I want to place a button on the browser screen that will call this method and send it a string.

When the method gets the string, it uses it to query the database, then creates and exports the file for me.

Where do I need to place this method, and what needs to be done for me to call the method with the button push?

Thanks,

Luke

Hello!
Such kind of actions (loading data, creating files, etc) is usually executed on the middleware tier, so you should create a service that will be executed on the middleware tier. It can be easily done with the CUBA Studio:
public://attachments/35306a6b9f6db3301e17f19722b5a09b.png
CUBA Studio will create an interface and its implementation. The only thing you should to do is to add your logic.
Then you should create a button and set it a method name that will be invoked:
public://attachments/c943dece4b6f59173e062465d757edbb.png
And as the final step, you should inject your service and invoke method:
public://attachments/53901f2731dbbe01cc90dc4121e1bd36.png
Best regards,
Daniil.

35306a6b9f6db3301e17f19722b5a09b

c943dece4b6f59173e062465d757edbb

53901f2731dbbe01cc90dc4121e1bd36

1 Like

See also the Organizing Business Logic section of the docs.

Thanks Daniil!

I created the method and added the code in all the right places, but now when I try and build / run the project I’m running into this error:
2017-10-24 13:11:09.012 ERROR [localhost-startStop-1] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.haulmont.cuba.web.jmx.ConfigStorage@71e102e4] with key ‘app.cuba:type=ConfigStorage’; nested exception is javax.management.InstanceAlreadyExistsException: app.cuba:type=ConfigStorage

Since this new code is the only thing I’ve added, I figure the addition of my method is the problem.

Know where I might have gone wrong?

Thanks,

Luke

Could you share spring.xml & web-spring.xml files from your project?

spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">

    <!-- Annotation-based beans -->
    <context:component-scan base-package="com.company.taxonomy"/>

</beans>

web-spring.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd"
       xmlns:context="http://www.springframework.org/schema/context">
    <!-- Annotation-based beans -->
    <context:component-scan base-package="com.company.taxonomy"/>
   <bean class="com.haulmont.cuba.web.sys.remoting.WebRemoteProxyBeanCreator">
        <property name="serverSelector"
                  ref="cuba_ServerSelector"/>
        <property name="remoteServices">
            <map>
                <entry key="taxonomy_ExportDSAsTSVService"
                       value="com.company.taxonomy.service.ExportDSAsTSVService"/>
            </map>
        </property>
    </bean>
</beans>

Thanks in advance for the help!

Update, there was a junk file somewhere in my commit that was causing the break. I made a clean commit of my code and the new build worked just fine. Looks like I need to be more specific / selective with my .gitignore.

Thanks again for all the help here, Daniil.

We can consider this matter closed.

You are welcome!