Customizing Global Entity Item Representation

It is possible to specify how entity items will be displayed in domain views of other entities that have persistent fields associated with this entity.

This is configured in the EntityMetadataConfigurationUnit of the entity administration, and affects all views of other entities where the persistent association field is used implicitly or explicitly.

There are two options to define custom entity representation:

1. Specifying one of the entity fields:


public class UserAdministration extends AdministrationConfiguration<User> {

	public EntityMetadataConfigurationUnit configuration( EntityMetadataConfigurationUnitBuilder configurationBuilder ) {
		return configurationBuilder.nameField( "firstname" ).build();
	}

}

Given the following Discount Program entity administration…


public class DiscountProgramAdministration extends AdministrationConfiguration<DiscountProgram>{

	public static EntityMetadataConfigurationUnit configuration( EntityMetadataConfigurationUnitBuilder configurationBuilder ) {
		return configurationBuilder
				.nameField( "name" )
				.pluralName( "Discounts" ).build();
	}

	public FieldSetConfigurationUnit listView( FieldSetConfigurationUnitBuilder fragmentBuilder ) {
		return fragmentBuilder
				.field( "name" ).caption( "Name" )
				.field( "users" ).caption( "Customers" ).build();
	}

	public FieldSetConfigurationUnit quickView( FieldSetConfigurationUnitBuilder fragmentBuilder ) {
		return fragmentBuilder
				.field( "name" ).caption( "Name" )
				.field( "users" ).caption( "Customers" ).build();
	}

	public FieldSetConfigurationUnit showView( final FieldSetConfigurationUnitBuilder fragmentBuilder ) {
		return fragmentBuilder
				.field( "name" ).caption( "Name" )
				.field( "users" ).caption( "Customers" ).build();
	}

	public FieldSetConfigurationUnit formView( final PersistentFieldSetConfigurationUnitBuilder fragmentBuilder ) {
		return fragmentBuilder
				.field( "name" ).caption( "Name" )
				.field( "users" ).caption( "Customers" ).build();
	}

	public FiltersConfigurationUnit filters( final FiltersConfigurationUnitBuilder filterBuilder ) {
		return filterBuilder
				.filter( "Name", "name" )
				.filter( "Customers", "users" ).build();
	}
}

…this will result in the following display of User entity items associated with Discount Program items:
Basic Display of Entity Item Name
2. Specifying advanced entity representation using org.lightadmin.core.config.domain.configuration.support.EntityNameExtractor:


public class UserAdministration extends AdministrationConfiguration<User> {

public EntityMetadataConfigurationUnit configuration( EntityMetadataConfigurationUnitBuilder configurationBuilder ) {
 return configurationBuilder.nameExtractor( userNameExtractor() ).build();
 }

private static EntityNameExtractor<User> userNameExtractor() {
 return new EntityNameExtractor<User>() {
 @Override
 public String apply( final User user ) {
 return String.format("%s %s", user.getFirstname(), user.getLastname());
 }
 };
 }
}

This will produce the following result:
Advanced Display of Entity Item Name