PDA

View Full Version : Bad generics in MultiField


sdc
02-23-2009, 12:06 PM
Hi,

I'm not sure to see why there is the F type parameter in MultiField class. If we use it, we can only add one type of field in a MultiField.
Also, MultiField<F extends Field> extends Field<F> means that MultiFields handle a value the type of which is Field and I don't think anoyone wants to keep a value the type of which is Field in a Field.
So I suggest :
MultiField<F extends Field> extends Field<F>to be replaced by
MultiField<D> extends Field<D>

Martin.Trummer
02-24-2009, 02:58 PM
well, I guess the MultiField is ok for Combo- and Radiogroups.

But I would also like to have another version without this restriction, much like your suggestion:
it would be nice to have a BaseMultiField that could handle different Fields for one type of data:
e.g. I want to have a DateTimeField that has datatype Date and internally has 2 fields: 1 DateField and one TimeField

PSEUDO-code:
what is now MultiField could become this

public class BaseMultiField<D> extends Field<D> {

protected List<Field<?>> fields;
...
}
then the new MultiField could extend this new class:

public class MultiField<D> extends BaseMultiField<Field<D>> {
...
}
and my date-time field would look like this:

public class DateTimeField extends BaseMultiField<Date> {

private final TimeField timeField;
private final DateField dateField;

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

@Override
public Date getValue() {
Date result = dateField.getValue();
if (result == null) {
return null;
}
return DateHelper.addTimeToDate(result, timeField.getValue());
}

@Override
public void setValue(Date value) {
dateField.setValue(DateHelper.getDatePart(value));
timeField.setValue(DateHelper.getTimePart(value));
}
}

sdc
03-27-2009, 04:01 AM
@Ext team : what do you think of it ? Can we expect a fix for 2.0 release ?

zaccret
04-01-2009, 12:41 PM
+1 (and basically +1 for all generics fixes)

sdc
05-05-2009, 05:08 AM
Well, I've writed my own MultiField. I've just changed the declaration :
public class MultiField<D> extends Field<D>and replaced F occurences by Field<?>.

It works well.

darrellmeyer
05-08-2009, 10:07 AM
We have changed MultiField to this:

public class MultiField<D> extends Field<D>Change is in SVN for 2.0.

sdc
05-12-2009, 07:35 AM
Thanks Darell.

These changes would also be greatly appreciated :
http://extjs.com/forum/showthread.php?p=324635#post324635
http://extjs.com/forum/showthread.php?p=324634#post324634
(especially the latter)