Is it possible to use CustomFiel add-on in combination with JPAContainer??

Hi All,

since I have not received any response from my previouse post
JPAContainer + Nested Item
, I kindly ask if some one can help me on using the CustomFiel add-on in combination with JPAContainer. Firt of all it is possible? Furthermore I’ll explain my situation: I’ve an entity class called “OrganizationUnit” that uses an object as a field called “OrganizationLevel”. I wold like to use a ComboBox where to select the OrganizationLevel type when creating a new OrganizationUnit. so I’ve created this customfield:


public class OrganizationLevelField extends FieldWrapper<OrganizationLevel> {

    private VerticalLayout layout;

    public OrganizationLevelField(Container container) {
        super(new ComboBox(), null, OrganizationLevel.class);
        layout = new VerticalLayout();
        layout.setMargin(false);
        layout.setSpacing(true);
        final ComboBox organizationLevelBox = new ComboBox(null, container);
        organizationLevelBox.setItemCaptionPropertyId("organizationLevel");
        organizationLevelBox.setInputPrompt("Livello Organizzativo");
        organizationLevelBox.setImmediate(true);
        layout.addComponent(organizationLevelBox);        
        setCompositionRoot(layout);
    }
}

The form used to create a new OrganizationUnit uses the class “OrganizationUnitFieldFactory” wich extends DefaultFieldFactory. The peace of code where to return the combobox for the OrganizationLevel is as following:


if (propertyId.equals("organizationLevel")) {
                return new OrganizationLevelField(organizationLevelContainer);
            }

where the organizationLevelContainer is the JPCContainer providing the organizationLevel objects.


@Resource(name = "organizationLevelProvider")
private EntityProvider<OrganizationLevel> organizationLevelProvider;
private JPAContainer<OrganizationLevel> organizationLevelContainer =new JPAContainer(OrganizationLevel.class);

// ...

organizationLevelContainer.setEntityProvider(organizationLevelProvider);

// ...

The problem occurs when I save the OrganizationUnit object and the the nested OrganizationLevel is always null.

Can someone please help me?? Thanks in advance.

Cris.

Hi Cristofer. OrganizationLevel is a ManyToOne from organization?

If is it, you can use a normal field, and a normal BeanItemContainer. Do you have thousands of OrganizationLevels?. Creating a combobox as you do is correct, because providing a field factory, the form component will bind your combo on the item of the itemDatasource. In this way, when you select an item from the list, this will cause a setValue on the propert, and a setOrganizationLevel on the Pojo on commit.

Hi Eduardo,
thanks for your response. Actually I was wondering if someone would have responded. Well since many days have been passed I’ve solved the problem by using a FieldWrapper , wich wraps a combobox for selecting the OrganizationLevel and yes, the relationship is bound to ManyToOne. The only problem I’ve occured was due the conversion between the ID and The Item. I’ve solved this problem by using something similar to EntityFieldWrapper. See
this thread
. Now is working fine.