View Full Version : GXT DateTimeField?

3 Jan 2012, 2:00 PM
In our apps we often have to set specific dates and times (i.e. a date without a time is to vague). Does GXT have a component that sets both? I see the DateField and TimeField but didn't see a way to combine them, is this possible? I'd be okay with the DateField with spinners at the bottom to set hours:minutes:seconds, etc.

4 Jan 2012, 12:08 AM
You can build it using a MultiField

The example below is not tested but should give you a good startingpoint.

public class DateTimeField extends MultiField<Date> {

private final TimeField timeField;
private final DateField dateField;

public DateTimeField() {
dateField = new DateField();
timeField = new TimeField();

public Date getValue() {
Date result = dateField.getValue();
if (result == null) {
return null;
return new Date(result.getTime() + timeField.getValue().getDate().getTime());

public void setValue(Date value) {
dateField.setValue(new Date(value.getYear(), value.getMonth(), value.getDate()));
timeField.setValue(new Time(value.getHours(), value.getMinutes()));

4 Jan 2012, 10:27 AM
I'm not finding the MultiField<> type in 3.x is there something equivalent?

Colin Alworth
4 Jan 2012, 9:27 PM
I've built such a thing subclassing Field (or AdapterField) in 2.x. As mentioned, MultiField could also work in 2.

In 3, I'd probably start by making an Editor instance with two sub-editors, one DateField and one TimeField, each using @Path("") to have them bind to the same value.

Or make the new class implement IsField, and use setValue() and getValue() to modify/read both sub-editors.

IsField is what is being used in 3 to replace most MultiField cases - it allows a widget to supply methods that are helpful for most fields, and as it extends LeafValueEditor, it can be used in GWT Editor framework, and subfields will be ignored, leaving the dev to write their own logic for binding the values.