Default
From JRapid
The "default" attribute of a property indicates the value which the property is going to take by default. You are encouraged to use default values as it is a good practice for user-friendly applications.
This attribute is not supported for collection properties.
Contents |
Usage:
<property
...
type = "type"
entity = "entity"
(NOT SUPPORTED) collection="set|list|..."
default = "Primitive value or an EL expression"
...
/>
Default values for properties which are not of type Entity:
You can set default values for all type of properties. For properties which are of type Entity you should use an EL expression (see below this examples).
- "integer":
<property type="integer" default="100" display="primary" label="Price" name="price" />
- "string":
<property type="string" default="'Enter a comment for this company...'" display="primary" label="Comments" name="comments"/>
- "date"
<property type="date" default="'04/08/2010'" display="primary" label="Comments" name="comments"/>
- You can use the "now" keyword which is an EL expression for getting the actual date.
<property type="date" default="now" display="primary" label="Comments" name="comments"/>
- "email"
<property type="email" default="'user@jrapid.com'" display="primary" label="Comments" name="comments"/>
Using EL expressions to load default values:
You can use an EL expressions for loading default values for properties of type Entity or loading dynamic default values.
<property type="date" default="now" label="Date" name="date" />
<property entity="Company" default="Company:findOneBy('isDefault', true)" label="Company" name="company"/>
A commonly used design pattern is to store the application's default values in a "Configuration" entity. This is very useful if you are designing your a application to be multitenant. Examples:
<property type="string" default="Configuration:find(1).defaultName" label="Name" name="name" />
<property type="date" default="Configuration:find(1).defaultDate" label="Name" name="name" />
<property entity="Company" default="Configuration:find(1).defaultComapany" display="primary" label="Date" name="date"/>
