Lookup field error

while I’m new, I think I’ve pretty much exhausted the documenation on the method to set value options for LookUp and Picker fields. Unfortunately, I keep getting the same error:

ClassCastException: class com.company.planner.entity.SessionType cannot be cast to class java.lang.String (com.company.planner.entity.SessionType is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @773f7880; java.lang.String is in module java.base of loader ‘bootstrap’)

What I am trying to achieve is fairly simple: Set a text value in a record from a drop down list of values (picker or lookup) from another table. Both source and destination fields are String. To illustrate the propblem, I used the QuickStart Session Planner demo, and added a new entity of SesstionType. This has only 1 field in it “name” and the name pattern on the entity is @NamePattern(“%s|name”). I simply want to pick one of these values (SessionType.Name) in the table and store the text in the new field “type” on Session entity. (I don’t want an ID reference)

The field “type” shows up in the browser and edit screens for Session, but navigating to the Session-edit screen gives the error above. (prior to any data entry.)
The session-edit.xml file is below.

I have reviewed the Sampler docs (https://demo10.cuba-platform.com/sampler/#main/8/sample?id=related-entity-lookupfield) and the Manual docs (LookupField - CUBA Platform. Developer’s Manual) for both LookUp and PickerLookUp.
Am I missing something? Does something need injecting into the controller?

Thanks.
-Curt

<data>
    <instance id="sessionDc"
              class="com.company.planner.entity.Session" >
        <view extends="_local">
            <property name="speaker" view="_minimal"/>
        </view>
        <loader/>
    </instance>
    <collection id="typesDc" class="com.company.planner.entity.SessionType" view="_local">
        <loader id="sessionTypesDl">
            <query>
                <![CDATA[select e from planner_SessionType e]]>
            </query>
        </loader>
    </collection>

</data>
<dialogMode height="600"
            width="800"/>
<layout expand="editActions" spacing="true">
    <form id="form" dataContainer="sessionDc">
        <column width="250px">
            <textField id="topicField" property="topic"/>
            <lookupField id="typeField" optionsContainer="typesDc"  property="type" />
            <dateField id="startDateField" property="startDate"/>
            <textField id="durationField" property="duration"/>
            <textArea id="descriptionField" property="description" rows="5"/>
            <dateField id="endDateField" property="endDate"/>
            <pickerField id="speakerField" property="speaker"/>
        </column>
    </form>
    <hbox id="editActions" spacing="true">
        <button action="windowCommitAndClose"/>
        <button action="windowClose"/>
    </hbox>
</layout>

Hello @curt.huffman

You could use LookupField#setOptionsList() method in screen controller to set options for drop down list.

    @Inject
    private CollectionLoader<SessionType> sessionTypesDl;
    @Inject
    private LookupField<String> typeField;
    @Inject
    private CollectionContainer<SessionType> typesDc;

    @Subscribe
    public void onBeforeShow(BeforeShowEvent event) {
        sessionTypesDl.load();

        List<String> sessionTypeNames = typesDc.getMutableItems().stream()
                .map(SessionType::getName)
                .collect(Collectors.toList());
        typeField.setOptionsList(sessionTypeNames);
    }

Regards,
Gleb

Thanks, Gleb.

I have been able to get it to work through java code in the controller to load values in the optionscontainer based on the example from:

It works as expected. (I substituted a separate entitiy for the look up options container.)

Please allow me to clarify:
My question is a bit broader as a newbie to Cuba: I expected that Cuba Studio would do this sort of basic stuff for me to save time. That’s how I understand the Developer’s manual references. They give examples of either specifying the optionsContainer in the xml with a DC, OR specifying it programatically in the controller. The implication is that either one will work.
While I understand that the returned dc contains object instances, is there further xml parameters that must be set to get the values I want from the instances?

Am I misunderstanding the docs? Is this just a bug in studio? Am I expecting too much of what Cuba Studio will automate?

Hello @curt.huffman

Unfortunately, you will not be able to solve your problem using the XML.

You could change the type of typeField from String to SessionType and use the captionProperty XML attribute or the LookupField#setOptionCaptionProvider method to customize the display of the option caption.

Regards,
Gleb