LookupField captionproperty

I am passing a collectiondatasource from Parent to a abstractLookup - LookupField.

I believe i have passed all the right parameters but instead of compName , I am get the full entity class name with id. What am i missing here ?

<b>public class </b>Searchcomp <b>extends </b>AbstractLookup
{
    @Inject
    <b>private </b>LookupField <b>lookupFieldSearch</b>;

    @Override
    <b>public void </b>init(Map<String, Object> params)
    {
        CollectionDatasource compDs = (CollectionDatasource) params.get(<b>"comp"</b>);
        <b>lookupFieldSearch</b>.setOptionsDatasource(compDs);
        <b>lookupFieldSearch</b>.setCaptionProperty(<b>"compName"</b>);

    }
}

Before setting caption property, set the caption mode:

lookupFieldSearch.setOptionsDatasource(compDs);
lookupFieldSearch.setCaptionMode(CaptionMode.PROPERTY);
lookupFieldSearch.setCaptionProperty("compName");

It is done automatically only when you set caption property from XML descriptor.