Table of Contents
In an app, we have to deal with various types of attributes. While
many of them have a standard datatype, like
String, as their range, some of them may have special datatypes
as their range. For instance, the Universal Business
Language (UBL), which is an industry standard defining document
formats for electronic commerce, defines a large set of business datatypes
including the following.
|UBL Data Type
|One calendar day according to the Gregorian calendar.
|An instance of time that occurs every day.
|A particular point in the progression of time, together with relevant supplementary information.
|Numeric information that is assigned or is determined by calculation, counting, or sequencing and is expressed as a percentage.
|A number of monetary units specified using a given unit of currency.
The Semantic MediaWiki uses the following special datatypes.
|Semantic MediaWiki Data Type
|Holds coordinates describing geographic locations
|To associate a text value with a specific language code
|Holds values that describe quantities, containing both a number and a unit
|Allows saving compound property values that consist of a short list of values with fixed type and order
|Holds e-mail addresses
|Holds URIs, URNs and URLs
|Holds international telephone numbers based on the RFC 3966 standard
We discuss several important cases of special datatypes and how to deal with them in the model code and in the HTML user interface code. The following class diagram illustrates examples of attributes having such a special datatype as their range.
Boolean attributes, like
isSmoker, can only have one of
two possible values: true or false, which are sometimes more naturally
expressed with yes or no. In the model code, Boolean attributes are
treated like primitive datatype attributes, since all programming
languages support Boolean as a
For rendering a Boolean attribute in a user interface, there are several options. The simplest solution is using a checkbox field. Alternatively, a single-selection list with the two options true and false (or yes and no), or a corresponding radio button group with two radio buttons, could be used.
In an HTML form, a checkbox field is implemented with an
input element of
checkbox. For assigning the value of the checkbox field to the Boolean
attribute, the field's
checked attribute has to be used, as shown in the following
example where we have a checkbox field in an HTML
Is smoker: <input type="checkbox" name="isSmoker" />
is assigned by reading the field's
checked attribute (instead of its
value attribute), like
var isSmokerCheckboxField = document.forms["Person"].isSmoker;
var newPerson = new Person(...);
newPerson.isSmoker = isSmokerCheckboxField.checked;