LookupField not displaying any values

Hi,

I am still experimenting with CUBA.platform and I am trying to create a screen that shall be displayed by clicking a button I have added to an existing generic view. I need somewhere to collect a set of parameters so that I can then ‘bulk’ add a set of records (I shall do the inserts in a bean on the middleware level). I want this as for the project I have in mind I have to quickly add in lists of location records and I want a quick way of doing this i.e. bulk create a set of records for positions 1 to 20 with a specified set parameters and repeat as necessary.

I have managed to add in a screen and if I open the Java file I can see it extends AbstractWindow. I have eventually figured out how to open it by using this code in the button handler:

openWindow(“BulkLayoutCreate”, WindowManager.OpenType.DIALOG);

Following the xample here (LookupField - CUBA Platform. Developer’s Manual) I have added a couple of datasources and linked these to two LookupField objects. Here is the xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://caption"
        class="com.carron.shelltracker.web.screens.Bulklayoutcreate"
        messagesPack="com.carron.shelltracker.web.screens">
   <dsContext>    
        <datasource id="recipeItemDs"
                              class="com.carron.shelltracker.entity.RecipeItem"
                              allowCommit="false"
                              view="_local"/>
                             
        <datasource id="suppliersDs"
                              class="com.carron.shelltracker.entity.Supplier"
                              allowCommit="false"
                              view="_local"/>
           
</dsContext>
<layout expand="buttonsBox"
            spacing="true">
        
        <lookupField datasource="recipeItemDs" property="recipe"/>
        
        <lookupField datasource="suppliersDs" property="code"/>
        
        <hbox id="buttonsBox"
              spacing="true">
            <button id="okBtn"
                    caption="OK"
                    invoke="onOkBtnClick"/>
            <button id="cancelBtn"
                    caption="Cancel"
                    invoke="onCancelBtnClick"/>
        </hbox>
    </layout>
</window>

However when I run the application although the dropdowns are shown they do not have any values:

image

Can anyone tell what I am doing wrong or what I am missing?

Thanks,
Iain

I should add that I know the entities have values. For example here is the RecipeItem:

image

Hi,

can you explain in a little more detail what you want to achieve? Then it will be much easier to give you a working example. Just in terms of:

“I want to create multiple receipItems when I create a supplier” or something along those lines.

Up until now I did not really understand what you are trying to achieve…

Bye
Mario

You have bound the fields to the datasources, but these datasources do not contain any data. You could load it programmatically in init() method and set to datasource using its setItem() method, but I think it is not what you need.

Take a look at this cookbook recipe: Returning Values from an Invoked Screen, specifically to the Returning a value from an arbitrary screen section. Here the customer-list screen shows a lookup field with the list of customers, and OrderEdit uses it to select a customer.

Hi Konstantin,

Thank you for that, much appreciated. I knew that I was missing something obvious. In addition I shall look at the suggested examples.

Kind regards,
Iain

Hi Mario,

I have an existing system which I would like to rebuild and I think it might be good to use Cuba. As part of the learning effort and evaluation of the platform I am trying to replicate, or improve upon, small chucks of the application.

So the application is used in the aquaculture industry and one of the key requirements is to maintain a location map of all the stock. That is the farm has a map of location points, several thousand in total, and for each batch being moved through the farm there is a need to map exactly where each ‘item’, that constitutes the batch, is located. In addition to that each ‘item’ has a set of parameters associated with it, referred to as the recipe, such as load (number of animals) for example.

Due to the nature of how the farm is worked there shall be times when the list of locations for a batch shall need to created or updated either in full or partially. In the current application the user has to fill in a big spreadsheet and then load this into the system and the locations are updated as appropriate.

That involves a lot of typing and there can be issues with maintaining the consistency of static / lookup data across the spreadsheet and the system. So I would like to get rid of this import facility if possible.

Obviously just building a generic CRUD screens shall work but it becomes completely impractical when there are hundreds of records, and that is why the spreadsheet solution appeared.

After looking at the ‘Bulk update’ option detailed in the manual I had a thought that I could create my own version for the initial load. The thinking is that although there can be several hundred records, these records shall exhibit the same pattern, or patterns, and due to the way the farm is worked they are set out in consistent patterns, i.e.

Items 1 to 50 (Recipe A) are in locations 100 to 150
Items 51 to 200 (Recipe B) are in locations 101 to 250
etc

As such I should be able to create a bespoke screen where I can set the start position, end position and recipe and then bulk create the records. Repeat this as necessary for each chunk. I shall also then have the CRUD screens to do any specific one off adjustments. As such I then have a nice way to handle this large scale data insert activity.

If you have any thoughts I would be happy to hear them.

Regards,
Iain

Hi,

I am still struggling to get this to work. Following along from the example Konstantin provided (sample-generic-ui/customer-list.xml at master · cuba-platform/sample-generic-ui · GitHub) I have updated my xml as such to use a collectionDatasource:

image

In the associated Java file I have added an init() and called refresh() as is done here (sample-generic-ui/CustomerList.java at master · cuba-platform/sample-generic-ui · GitHub):

image

I had hoped that this would drive the load of data in the screen but I am still not seeing any items:

image

I am obviously doing something stupid but I am just going round in circles at the moment. Any help appreciated.

Thanks,
Iain

hi,

the problem is, that in your XML file there is an error. In the lookupfield with id “recipeField” you need to add the attribute optionsDatasource="receipeItemsDs" instead of openDatasource. Additionally the selected value (in this case the recipeItem) should be saved somewhere, correct? Therefore thelookupField needs an attribute datasource="supplierDs" as well as property="recipeItem" (depending on how the attribute of the supplier is named that will store the reference to the reciepeItem.

The manual loading via the init method is not needed in this case…

That should do the trick.

Bye
Mario

Also, programming with CUBA is much easier in IntelliJ… It would show your mistake with XML attribute right away.

Ok, looks like I might have to trade in Eclipse then. Ah like getting rid of a family pet… :slight_smile:

Yeh something stupid like I said then…

Ok I have made the updates as suggested and all is working now.

Really appreciate the help.

Regards,
Iain