PDA

View Full Version : Bad generics in MultiField



sdc
23 Feb 2009, 9:06 AM
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
24 Feb 2009, 11:58 AM
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
27 Mar 2009, 12:01 AM
@Ext team : what do you think of it ? Can we expect a fix for 2.0 release ?

zaccret
1 Apr 2009, 8:41 AM
+1 (and basically +1 for all generics fixes)

sdc
5 May 2009, 1: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
8 May 2009, 6:07 AM
We have changed MultiField to this:


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

sdc
12 May 2009, 3: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)