Customizing views
Each view is represent by an EntityViewFactory
.
An EntityViewFactory
can easily be customized on an EntityConfigurationBuilder
through the use of EntityViewFactoryBuilders
.
They allow for various customizations, such as customizing the property registry and registering view processors.
When specifying multiple entity configurers, they will be applied in order.
@Override
public void configure( EntitiesConfigurationBuilder entities ) {
entities.withType( Book.class )
.formView( "publication", (1)
fvb -> fvb.showProperties( "publication.*" ) (2)
);
}
1 | Configure a form view with name publication. |
2 | Show all the properties of the publication property of the Book . |
In the following sections, you’ll find more detailed information on global configuration options for view factories.
Configuring properties
Most often, views will render properties for a specific purpose, being the ability to view, modify or delete data.
As such, an EntityPropertyRegistry
can be attached to a view that holds the metadata for those properties.
When a property registry is attached, this registry can be further customized by specificying additional EntityPropertyRegistryBuilders
.
A selection of these properties can then be provided which should be rendered by default.
Properties are then rendered with a specific purpose in mind.
To render properties accordingly, a ViewElementMode
can be specified to define how those properties should be rendered by default.
Name | Description |
---|---|
|
Provide the property registry that should be attached to the view.
If configured, an |
|
Customize the properties using by providing an |
|
Specify which properties should be rendered by listing property names or configuring an |
|
Configures which |
Customizing request execution
EntityViewProcessors
allow you to hook into the lifecycle of the view request.
They can easily be registered, removed or customized on an EntityViewFactoryBuilder
.
Name | Description |
---|---|
|
Register an |
|
Remove a previously registered view processor. |
|
Modify a registered view processor. This can be used for example to modify properties of a view processor. |
Attributes
Attributes can be registered on an EntityViewFactory
which can then be used during the request execution.
Each attribute is represented as a key-value pair where the key is a string
.
See the appendix for a list of available attributes.
entities.withType( Book.class )
.formView( "publication",
fvb -> fvb.attribute( EntityAttributes.FORM_ENCTYPE, FormViewElement.ENCTYPE_MULTIPART )
);
Controlling access
Access to views can be restricted by setting a required AllowableAction
.
If the authenticated principal does not have access to the action, access to the view will be denied.
The allowable action that is set on the EntityViewFactory
is checked by the ActionAllowedAuthorizationViewProcessor
.
Access to the view can also be customized through EntityViewProcessors
by implementing the authorizeRequest
method.
entities.withType( Book.class )
.formView( "publication",
fvb -> fvb.requiredAllowableAction( AllowableAction.READ )
);
Messages & Localization
During the view request various message codes will be resolved. A view allows you to define the prefix that should be used when resolving these message codes.
entities.withType( Book.class )
.formView( "publication",
fvb -> fvb.messagePrefix( "publicationView" ) (1)
);
1 | A message code for the publication view will be resolved using EntityPrefix.adminMenu.publicationView instead of EntityPrefix.adminMenu.views[viewName] |
See the appendix for more information on message codes.
Setting the message prefix for a view will remove the previously configured message prefixes.
It will register a new |