Default (attribute of property)
From JRapid
(Redirected from Default)
default is an attribute of property.
Contents |
Description
The default attribute specifies the value that a property takes when a form for a new record is opened. You are encouraged to use default values as it is a good practice for user-friendly applications.
The default value expression is an EL expression.
This attribute is not supported for collection properties.
Note that default values specified through this attribute are not set when a new entity record is created using a defaultset. You must define again this default values in the defaultset as required.
Usage
<property
...
type = "type"
entity = "entity"
(NOT SUPPORTED) collection="set|list|..."
default = "Primitive value or an EL expression"
...
/>
Example
- For properties of type "integer":
<property type="integer" default="100" display="primary" label="Price" name="price" />
- For properties of type "string":
<property type="string" default="'Enter a comment for this company...'" display="primary" label="Comments" name="comments"/>
- For properties of type "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 current date.
<property type="date" default="now" display="primary" label="Comments" name="comments"/>
- For properties of type "email"
<property type="email" default="'user@jrapid.com'" display="primary" label="Comments" name="comments"/>
- For properties of type "enum"
<entity label="Company" menu="Menu" name="Company">
<property display="primary" label="Name" name="name"/>
<property default="'C'" label="Status" name="status" type="enum">
<enum value="N">New</enum>
<enum value="C">Customer</enum>
<enum value="D">Discarded</enum>
</property>
</entity>
- You can use an EL expression for setting default values for entity-type properties.
<property type="date" default="now" label="Date" name="date" />
<property entity="Company" default="Company:findOneBy('isDefault', true)" label="Company" name="company"/>
<entity label="Company" menu="Menu" name="Company">
<property display="primary" label="Name" name="name"/>
<property default="Country:findOneBy('name', 'USA')" entity="Country" label="Country" name="country"/>
</entity>
- A commonly used design pattern is to store the application's default values in a "Configuration" entity. This is very useful if you want your application to be easily configured during runtime. 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"/>
