Implementing Categories

Hello, im building a simple inventory app, it has the “product” entitty with the regular fields:
name, productCode, quantity, notes.

Since it would be useful to also have inventory of spare parts, i figured on adding categories (SparePart and Product) with dynamic attributes, for example, a “used” field in the spare part category.

Im struggling on understanding some concepts in documentation, while i created needed data in Category editor, i cant find how to display them in editor or browser.

My next step is to create datasource, this is the part im confused about, the dock mentions a new api in version 7, but i find no mentions on creating datasources or using data components for categories.
My xml only has instance and loader elements.

Hi Luis,

The RuntimePropertiesFrame component which is capable of displaying categories and dynamic attributes works only in screens based on the legacy API. So create your product browse screen from the “Entity browser” template available on the “Legacy Screen Templates” tab of the screen creation wizard.

1 Like

Ok, thank you very much. Do i need to go the same route to display a singe attribute?

EDIT: figured out :slight_smile:

I’ve an issue going the legacy path, I’ve created a legacy view and inserted the properties Frame but I have an exception:

java.lang.IllegalArgumentException: Could not resolve property path 'category' in 'fabistock_Producto'
	at com.haulmont.bali.util.Preconditions.checkNotNullArgument(Preconditions.java:124)
	at com.haulmont.cuba.gui.components.data.value.DatasourceValueSource.setBeanLocator(DatasourceValueSource.java:75)
	at com.haulmont.cuba.gui.components.data.value.ValueBinder.bind(ValueBinder.java:63)
	at com.haulmont.cuba.web.gui.components.WebAbstractValueComponent.setValueSource(WebAbstractValueComponent.java:50)
	at com.haulmont.cuba.gui.components.DatasourceComponent.setDatasource(DatasourceComponent.java:91)
	at com.haulmont.cuba.gui.components.RuntimePropertiesFrame.initCategoryField(RuntimePropertiesFrame.java:142)
	at com.haulmont.cuba.gui.components.RuntimePropertiesFrame.init(RuntimePropertiesFrame.java:112)
	at com.haulmont.cuba.gui.components.AbstractFrame.init(AbstractFrame.java:103)
	at com.haulmont.bali.events.EventHub.publish(EventHub.java:170)
	at com.haulmont.cuba.gui.screen.ScreenFragment.fireEvent(ScreenFragment.java:84)
	at com.haulmont.cuba.gui.screen.UiControllerUtils.fireEvent(UiControllerUtils.java:58)
	at com.haulmont.cuba.gui.xml.layout.loaders.FragmentLoader$FragmentLoaderInitTask.execute(FragmentLoader.java:256)
	at com.haulmont.cuba.gui.xml.layout.loaders.ComponentLoaderContext.executeInitTasks(ComponentLoaderContext.java:161)
	at com.haulmont.cuba.web.sys.WebScreens.createScreen(WebScreens.java:251)
	at com.haulmont.cuba.web.sys.WebScreens.create(WebScreens.java:171)
	at com.haulmont.cuba.gui.config.MenuItemCommands$ScreenCommand.run(MenuItemCommands.java:212)
	at com.haulmont.cuba.web.sys.MenuBuilder$MenuCommandExecutor.accept(MenuBuilder.java:256)
	at com.haulmont.cuba.web.sys.MenuBuilder$MenuCommandExecutor.accept(MenuBuilder.java:241)
	at com.haulmont.cuba.web.gui.components.mainwindow.WebAppMenu$MenuItemImpl.menuSelected(WebAppMenu.java:435)
	at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:225)
	at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:611)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:457)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:400)
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:260)
	at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:82)
	at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1577)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:425)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:329)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:215)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:107)
	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:108)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
<dsContext>
    <datasource id="productoDs" class="xyz.luisd.fabistock.producto.Producto" view="producto-viewCimage"/>
    <runtimePropsDatasource id="runtimePropsDs" mainDs="productoDs"/>
    <collectionDatasource id="categories" class="com.haulmont.cuba.core.entity.Category" view="_local">
        <query><![CDATA[select c from sys$Category c where c.entityType='fabistock_Producto']]></query>
    </collectionDatasource>
    <groupDatasource id="productoesDs" class="xyz.luisd.fabistock.producto.Producto" view="_local">
        <query><![CDATA[select e from fabistock_Producto e]]></query>
    </groupDatasource>
</dsContext>

Any ideas what Im doing wrong?

Probably your fabistock_Producto entity is not implementing Categorized.
Inherit it from CategorizedEntity.

No, i think i’ve done that correctly:

@Entity(name = "fabistock_Producto")
@EnableRestore

public class Producto extends StandardEntity implements Categorized {

[…omitted code…]

@Override
public Category getCategory() {
    return null;
}

@Override
public void setCategory(Category category) {

}

Hi.
It is necessary that your entity has the association field with Category entity type or extends CategorizedEntity

@Entity(name = "demo_Product")
public class Product extends StandardEntity implements Categorized {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CATEGORY_ID")
    protected Category category;

    @Override
    public Category getCategory() {
        return category;
    }

    @Override
    public void setCategory(Category category) {
        this.category = category;
    }
}
1 Like