Tried adding a datasource to a textfield

GuiDevelopmentException: Can’t set datasource ‘totalCapacityDs’ for component ‘null’ because ‘property’ attribute is not defined.

I tried adding a text field which I need to display total capacity . I have created new datasource ‘totalcapacityDs’ towhich sum the capacity.

Could you please provide more info: screen descriptor and full stack trace?

Full Stack Trace.


com.haulmont.cuba.gui.GuiDevelopmentException: Can't set datasource 'totalCapacityDs' for component 'null' because 'property' attribute is not defined, frameId=waterschemenigeria$Scheme.browse 
    at com.haulmont.cuba.gui.xml.layout.loaders.AbstractDatasourceComponentLoader.loadDatasource(AbstractDatasourceComponentLoader.java:32) 
    at com.haulmont.cuba.gui.xml.layout.loaders.AbstractFieldLoader.loadComponent(AbstractFieldLoader.java:25) 
    at com.haulmont.cuba.gui.xml.layout.loaders.TextFieldLoader.loadComponent(TextFieldLoader.java:18) 
    at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:29) 
    at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:68) 
    at com.haulmont.cuba.gui.xml.layout.loaders.AbstractBoxLoader.loadComponent(AbstractBoxLoader.java:34) 
    at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponents(ContainerLoader.java:29) 
    at com.haulmont.cuba.gui.xml.layout.loaders.ContainerLoader.loadSubComponentsAndExpand(ContainerLoader.java:68) 
    at com.haulmont.cuba.gui.xml.layout.loaders.WindowLoader.loadComponent(WindowLoader.java:65) 
    at com.haulmont.cuba.gui.WindowManager.createWindow(WindowManager.java:170) 
    at com.haulmont.cuba.gui.WindowManager.openWindow(WindowManager.java:345) 
    at com.haulmont.cuba.gui.config.MenuCommand.execute(MenuCommand.java:87) 
    at com.haulmont.cuba.web.sys.MenuBuilder$1.menuSelected(MenuBuilder.java:153) 
    at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:207) 
    at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:508) 
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:327) 
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:202) 
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:95) 
    at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.lambda$synchronizedHandleRequest$67(CubaVaadinServletService.java:290) 
    at com.haulmont.cuba.web.sys.CubaVaadinServletService.withUserSession(CubaVaadinServletService.java:171) 
    at com.haulmont.cuba.web.sys.CubaVaadinServletService$CubaUidlRequestHandler.synchronizedHandleRequest(CubaVaadinServletService.java:290) 
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41) 
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1408) 
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:356) 
    at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:226) 
    at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:149) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at com.haulmont.cuba.web.sys.CubaHttpFilter.handleNotFiltered(CubaHttpFilter.java:100) 
    at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:87) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526) 
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    at java.lang.Thread.run(Thread.java:745)

Screen Descriptor


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="[url=http://schemas.haulmont.com/cuba/window.xsd]http://schemas.haulmont.com/cuba/window.xsd"[/url];
        caption="msg://browseCaption"
        class="com.company.waterschemenigeria.gui.scheme.SchemeBrowse"
        focusComponent="schemesTable"
        lookupComponent="schemesTable"
        messagesPack="com.company.waterschemenigeria.gui.scheme">
    <dsContext>
        <collectionDatasource id="schemesDs"
                              class="com.company.waterschemenigeria.entity.Scheme"
                              view="scheme-view">
            <query>
                <![CDATA[select e from waterschemenigeria$Scheme e]]>
            </query>
        </collectionDatasource>
        <collectionDatasource id="totalCapacityDs"
                              class="com.company.waterschemenigeria.entity.Scheme"
                              view="scheme-view">
            <query>
                <![CDATA[select SUM(e.capacity) from waterschemenigeria$Scheme e]]>
            </query>
        </collectionDatasource>
    </dsContext>
    <layout expand="schemesTable"
            spacing="true">
        <filter id="filter"
                applyTo="schemesTable"
                datasource="schemesDs">
            <properties include=".*"></properties>
        </filter>
        <hbox>
            <label value="Total Capacity:"
                   width="100px"></label>
            <textField datasource="totalCapacityDs"
                       datatype="double"
                       description="Total Capacity of the Water Tank"></textField>
        </hbox>
        <table id="schemesTable"
               width="100%">
            <actions>
                <action id="create"></action>
                <action id="edit"></action>
                <action id="remove"></action>
            </actions>
            <columns>
                <column id="locationName"/>
                <column id="waterscheme"/>
                <column id="capacity"/>
                <column id="status"/>
            </columns>
            <rows datasource="schemesDs"></rows>
            <rowsCount></rowsCount>
            <buttonsPanel id="buttonsPanel"
                          alwaysVisible="true">
                <button id="createBtn"
                        action="schemesTable.create"></button>
                <button id="editBtn"
                        action="schemesTable.edit"></button>
                <button id="removeBtn"
                        action="schemesTable.remove"></button>
            </buttonsPanel>
        </table>
    </layout>
</window>

I have attached the image for the error

image

Samuel,

First, the query in the totalCapacityDs datasource doesn’t correspond the specified class Scheme and view


        <collectionDatasource id="totalCapacityDs"
                              class="com.company.waterschemenigeria.entity.Scheme"
                              view="scheme-view">
            <query>
                <![CDATA[select SUM(e.capacity) from waterschemenigeria$Scheme e]]>
            </query>

Second, CUBA doesn’t support aggregate functions from the client side, because it cannot resolve security permissions for such fields. I would propose creating a service that provides you with the desired data, call this service from the controller (e.g. in init method of your screen) and fill out a text field.

P.S. We will consider ways to simplify the proposed approach and enable using aggregate functions from the client side. Thank you for pointing the place that can be improved!

Thanks, Worked with creating the service