The <tc:date/> tag create an input field for a date or time. The date can also be edited in the textfield.
<tc:date/>
Tag Library Documentation: <tc:date/> | <f:convertDateTime/>
A date can have a label. To get a label use the label attribute.
label
<tc:date label="Date" value="#{dateController.sputnikLd}"/>
The following date should be selected after reloading the page. This can be done with the attribute focus.
focus
<tc:date label="Date (focus)" focus="true"/>
For advanced business application users, browser-based date-picker might be too slow to use, because they are used to typing fast.
In this demo is an script file demo-date.ts to show a second input field for shortcuts. Just type e.g. 0212 for December, 2nd in the current year. The next input field will filled automatically and the date-picker can be used. This is activated by
demo-date.ts
<tc:dataAttribute name="quick-pattern" value="ddmm"/>
This script is just an showcase. A real application may use specially adjusted shortcuts. E.g. using also a 2-digit year or creating the special quick input field by a keyboard shortcut, or button.
tabIndex="-1"
New! It is NOT recommended to use <f:convertDateTime>, in most cases the converter will be configured automatically.
<f:convertDateTime>
The value must be one of a set of several types. There are some new classes from JEP 150 since Java 8, which are generally preferred to use (there are several discussions in the net).
value
Technical hint: Until Tobago 4 the user readable localized formatted String (e. g. 12/31/2050) was rendered into the HTML file and was post back to the server. New! Since Tobago 5 the string will be tranfered as ISO 8601 (e. g. 2050-12-31) to satisfy the HTML5 specification for input type="date", type="time" and type="datetime-local".
A date can be set as required with the required attribute. Such a date must contain a value, otherwise a submit is not possible. Leave the field blank and press 'submit' to see the error message.
required
<tc:date label="Date (required)" required="true" value="#{dateController.once}">
A Java date can also be displayed in other components. Please use an appropriate converter.
<tc:in label="Date in Textfield" value="#{dateController.today}"> <f:convertDateTime pattern="dd.MM.yyyy"/> </tc:in>
<tc:textarea label="Date in Text Area" value="#{dateController.today}"> <f:convertDateTime pattern="dd.MM.yyyy"/> </tc:textarea>
<tc:out label="Date in Output" value="#{dateController.today}"> <f:convertDateTime pattern="dd.MM.yyyy"/> </tc:out>
<tc:label value="#{dateController.today}"> <f:convertDateTime pattern="dd.MM.yyyy"/> </tc:label>
Styles can be set with the attributes dateStyle and timeStyle. Possible values are 'short', 'medium', 'long' and 'full'. It does not work with <tc:date/>, so here we use an output field.
dateStyle
timeStyle
To define the earliest or latest acceptable date, the attributes min and max can be used. The range in this example is from Mar 13, 2025 to Mar 20, 2025.
min
max
The size can be changed with markup large or small.
large
small
To define the earliest or latest acceptable date, the attributes min and max can be used.
Press the button to submit the date to the server. The output field show the current value. The date can be changed with the datepicker or by entering a valid date in the textfield.
The output field in this example, display the given date. With <f:ajax render="outputfield"/>, the <tc:out id="outputfield" .../> will be rerendered, after the date changed. The date can be changed by button or by entering a valid date in the textfield. If the date is not valid, it won't be adopted.
<f:ajax render="outputfield"/>
<tc:out id="outputfield" .../>