I created a service to create beanmodels like this:

public class BeanModelHelperImpl implements BeanModelHelper
{
/**
     * Create a BeanModel for a class from an ordered array of
     * Strings for the fieldnames.
     *
     * @param clazz  the class for which the model is to be built
     * @param fields the Fieldnames
     * @return the created BeanModel
     */
public BeanModel createBeanModel(Class clazz, String[] fields,
                                     BeanModelSource beanModelSource,
                                     ComponentResources componentResources)
    {
        HashSet<String> fieldNames = new HashSet<String>();

        for (String s : fields)
        {
            fieldNames.add(s.toLowerCase());
        }

        BeanModel beanModel = beanModelSource.create(clazz, false,
componentResources);

        List<String> actualProperties = beanModel.getPropertyNames();
        for (String s : actualProperties)
        {
            if (!fieldNames.contains(s.toLowerCase()))
                beanModel.remove(s);
        }
        beanModel.reorder(fields);
        return beanModel;
    }
}

If I call this with a line like

Beanmodel model = beanModelHelper.createBeanModel(Master.class, new
String[]{"name","slave.name","slave.enslaved", source, resources);

an exception is thrown:

Bean editor model for entities.Master does not contain a property named
'slave'. Available properties: name.

This is to be expected since the beanModel created by the beanModelSource
contains only the primitive (and Date) properties of any given class it
seems, so when I have a property which itself is a class with primitive
properties as in the example there seems to be no easy way get these into a
BeanModel save by creating a new class with the needed properties as a kind
of transferobject.

Reply via email to