Getting the usual "unfetched attribute" exception...but the attribute IS in the view

So I’ve got a need to add things onto the User entity, and since the recommended way now is to NOT extend the actual class, I’ve done it as a normal association. Except on the edit screen for the extra info I also need the user’s email there. I’ve added said attribute to the view, and that view is the one being used by the screen… but I still get ye olde unfetched attribute exception for the user’s email. I can’t figure out why.

And the weirder thing is, in happens also in the attached generated-in-2-minutes test project too.

Just build/run the project, go in, use the only screen “userstuffs” and pick a user. You’ll get the exception. Even though user.email is definitely in the view!

wtfuseremail.zip (82.2 KB)

Hi @jon.craig,

The problem happens only when you pick a user from the drop-down and this has a straightforward explanation: your options container returns a user with minimal view <collection id="usersDc" class="com.haulmont.cuba.security.entity.User" view="_minimal"> and this doesn’t include the email field. Just specify the right view of the usersDc. Here is your pill:

        <collection id="usersDc" class="com.haulmont.cuba.security.entity.User">
            <view extends="_minimal">
                <property name="email"/>
            </view>
            <loader id="usersLc">
                <query>
                    <![CDATA[select e from sec$User e]]>
                </query>
            </loader>
        </collection>

Also, let me suggest an improvement. You can traverse fields in the property attribute like user.email. Here is what you can do in your case:

<window xmlns="http://schemas.haulmont.com/cuba/screen/window.xsd"
        caption="msg://editorCaption"
        focusComponent="form"
        messagesPack="com.company.wtfuseremail.web.screens.userstuff">
    <data>
        <instance id="userstuffDc"
                  class="com.company.wtfuseremail.entity.Userstuff"
                  view="userstuff-edit-view">
            <loader/>
<!--        You don't need this nested data conatiner-->
<!--        <instance id="userDc" property="user"/>-->
        </instance>
         ...
    </data>
    ...
    <layout expand="scrollBox" spacing="true">
        <scrollBox id="scrollBox" spacing="true">
            <form id="form" dataContainer="userstuffDc">
                <column width="250px">
                    <lookupPickerField id="userField" optionsContainer="usersDc" property="user"/>
<!--                Just traverse through the graph directly-->
                    <textField id="userEmail" property="user.email"/>
                    <textField id="extrastuffField" property="extrastuff"/>
                </column>
            </form>
        </scrollBox>
        ...
    </layout>
</window>

Regards,
Aleksey

Of course. :frowning: I completely forgot about the options container! I was so focused on the main data container.