Changing getValue() type

I have question about overrining getValue() method. In my sytuatnion I have to make PopupDateField to return formated String insted of Date object. So I created class:

private class MyPopupDateField extends PopupDateField {
        private static final long serialVersionUID = 1L;

        public MyPopupDateField(String caption) {
        public Object getValue() {
            Date date = (Date) super.getValue();
            if (date == null)
                return date;
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
            String formattedDate = sdf.format(date);
            return formattedDate;

        public Class<?> getType() {
            return String.class;

but I am having conversion exceptions. Which methods should I also override (and how)?

The getValue() function might be called by some other part of the component and expect a Date (maybe the conversion between popup and field or the validator) and crash trying to use your overriden version.

The simplest would be to leave getValue() as it is and create getFormattedValue() or something like this to return the String. If you have to use getValue(), I would make a CustomComponent containing only a PopupDateField inside and wire CustomComponent.getValue() to do what you want.

In this case, using a FieldWrapper from the
CustomComponent add-on
might be the easiest way to perform the conversions.

Thanks for replays. I used CustomField to wrap PopupDateField and create MyCustomComponent as Mathias Clerc said. It is not perfect but it will do. Thx again.