DateTime
From Sense/Net 6.0 Wiki
Contents |
[edit] Summary
DateTime is used for defining a Field that stores a date and time value.
Data Type
At the core of the system the data type of a DateTime Field is DateTime RepositoryDataType. If the value assigned can not be converted to a DateTime the Field will not save that value and an error will occur (and exception will be thrown).
[edit] Example
This below is a fragment of the XML code of the Content Type Definition, which defines the operation of the given content's field. This fragment creates a field in the content type definition which users to enter binaries to the given content type.. As you can see this is done in a very simple way. This particular fragment is cut from a longer xml code, and it describes the field where you can specify any binary code of a content.
Minimal example
<Field name="FieldName" type="DateTime"> <Title>The Title Of The Field</Title> </Field>
Regular example
<Field name="Field" type="DateTime"> <Title>The Title Of The Field</Title> <Description>Description of the Field</Description> </Field>
Full featured example
<Field name="FieldName" type="DateTime"> <Title>The Title Of The Field</Title> <Description>Description of the Field</Description> <Bind property="ExistingPropertyName" /> <Configuration handler="SenseNet.ContentRepository.Fields.NullFieldSetting"> <Compulsory>true</Compulsory> <ReadOnly>false</ReadOnly> </Configuration> </Field>
Now let's see what these lines are responsible for.
<Title>The Title Of The Field</Title>
This line stands for the Title of the field in the Content Type Definition. Whatever you type here will be displayed on the datasheet of the given content.
<Description>Description of the Field</Description>
This line is responsible for displaying a short description of the required information you want users to enter.
<Configuration handler="SenseNet.ContentRepository.Fields.NullFieldSetting"> <Compulsory>true</Compulsory> <ReadOnly>false</ReadOnly> </Configuration>
- A custom FieldSetting can be defined by assigning value to the handler attribute of the Configuration tag. This is an advanced feature. (code 103)
- The Compulsory tag indicates whether the Field should be filled out. If it is true, empty value is not allowed.
- The ReadOnly tag decides whether the Field value can be changed within a View. When set to true the value cannot be changed (see ReadOnly fields and properties)
- The Bind tag indicates that the field should be mapped to the ExistingPropertyName property already defined in the system.
Here is an example of this field in practice:
<Field name="BirthDay" type="DateTime"> <Title>Your Birthday</Title> <Description>Please type in your date of birth here</Description> <Configuration> <Compulsory>true</Compulsory> </Configuration> </Field>
And this is how it will look like in Content Explorer:
Here you can give the whole window a good look, this window opens anytime you are about to create any content (with these attributes) using Content Explorer.
[edit] Defining default values
It is possible to define a default value for the DateTime field by altering the Content Type Definition.
Example:
<?xml version="1.0" encoding="utf-8"?> <ContentType ...> <Fields> <Field name="DateTimeField" type="DateTime"> <Configuration> <DefaultValue>2008-11-11 08:25:56</DefaultValue> ....
[edit] Function
When creating a new content, the default values will get written in the new modul control of the contentview, and they will be saved through this as well. There is an option to script the default value.
Example:
[Script:jScript]DateTime.Now[/Script]
From now on the scripting option can be used generally. Under SenseNet.Storage there is a "Scripting" namespace, in which IEvaluator interface is defined with a method: Evaluate (string source) The script engine is under the same namespace, as a static class called Evaluator. In this class there is a static string method, which has to be called by the string that contains one or more scripts. In the string given back the script parts will replaced by the evaluated elements.
The script part has to look like this: [Script:scriptname]script source code[/Script]. The value of the scriptname is defined by the ScriptTagNameAttribute on the evaluator class, the usage of this is compulsory. For now there's only one evaluator, this is stored in the SenseNet.ContentRepository.dll JscriptEvaluator.cs, and its tagname is "jScript" (case sensitive). System, System.Web and SenseNet.Storage are referenced, so pretty much everything is accessible.
The handling of the script engines will be the subject of further enhancement. As for now it runs by provider model, adding and deleting evaluators during run-time is not possible.


