Customize/format options in LookupField with OptionalDatasource

Seems the

WebLookupField

implementation only use

InstanceUtils.getInstanceName

to get the option strings from entity.
If we pass an entity

country

with 2 attribute

name

and

countryCallingCode

as datasource to a

LookupField

,
then we want options of the field displayed like

United States (+1)

and

China (+86)

etc.
how to get that?

Hi Kai,

in this case, you can Annotate your Country with the @NamePattern annotation like this:


@NamePattern("%s (%s)|name,countryCallingCode")
@Table(name = "TEST_COUNTRY")
@Entity(name = "test$Country")
public class Customer extends StandardEntity

If you need more options you can reference a method in the Annotation. For more information you can take a look at the java docs of @NamePattern.

Bye,
Mario

Thanks,

I still chose to keep

@NamePattern

as

name

only, it’s purposed.
The solution is to define a non-persist attribute that combine

name

and

countryCallingCode

,
then give it to a view, finally transferred to the screen.

Please also look at the captionProperty attribute of LookupField and other components implementing OptionsField. It allows you to display any attribute as an option, not only InstanceName.