View Full Version : GXT 3.0 PropertyAccess interface and iinheritance

14 Jan 2012, 6:29 AM

Regarding PropertyAccess interface and generators for ValueProvider etc, I have a question about using this interface with DTOs that extend other DTOs.

I have this scenario:

public class TypeDTO extends ModelDTO {

private String abbreviation;
private String name;
private Integer type;
private String status;
// getters & setters are hide for simplicity

public class MessureUnitDTO extends TypeDTO {

private String messureUnitCode;

public String getMessureUnitCode() {
return messureUnitCode;

public void setMessureUnitCode(String messureUnitCode) {
this.messureUnitCode = messureUnitCode;

Now in order to implement this I have defined the following interfaces:

public interface TypeDTOPropertyAccess<T extends TypeDTO> extends PropertyAccess<T> {

ValueProvider<T, String> abbreviation();

ValueProvider<T, String> name();

ValueProvider<T, Integer> type();

ValueProvider<T, String> status();

LabelProvider<MessureUnitDTO> label();


public interface MessureUnitDTOPropertyAccess extends TypeDTOPropertyAccess<MessureUnitDTO> {

ValueProvider<MessureUnitDTO, String> messureUnitCode();

ModelKeyProvider<MessureUnitDTO> key();


But this implementation is not working, when I run this I received the error:

[ERROR] [arballonwebtest] - Errors in 'generated://F2DFE1D83DE1FAF515E70944DB03F1CD/com/arballon/web/core/shared/model/types/parties/MessureUnitDTOPropertyAccessImpl.java'
[ERROR] [arballonwebtest] - Line 3: The type MessureUnitDTOPropertyAccessImpl must implement the inherited abstract method TypeDTOPropertyAccess<MessureUnitDTO>.name()
[ERROR] [arballonwebtest] - Line 3: The type MessureUnitDTOPropertyAccessImpl must implement the inherited abstract method TypeDTOPropertyAccess<MessureUnitDTO>.abbreviation()
[ERROR] [arballonwebtest] - Line 3: The type MessureUnitDTOPropertyAccessImpl must implement the inherited abstract method TypeDTOPropertyAccess<MessureUnitDTO>.label()
[ERROR] [arballonwebtest] - Line 3: The type MessureUnitDTOPropertyAccessImpl must implement the inherited abstract method TypeDTOPropertyAccess<MessureUnitDTO>.type()
[ERROR] [arballonwebtest] - Line 3: The type MessureUnitDTOPropertyAccessImpl must implement the inherited abstract method TypeDTOPropertyAccess<MessureUnitDTO>.status()

Maybe I miss something but it looks like inheritance is not supported for PropertyAccess generators. I was expecting that the generator will generates the methods of the interface and the methods of the super interface but for the error I received it seems it doesn't.

Any help will be appreciated.

Colin Alworth
15 Jan 2012, 9:41 AM
Thanks for the use case.

In the meantime as a workaround, you don't need to write your interface quite that way. Instead of using T in your methods, use TypeDTO - all the methods will be legal for subclasses of TypeDTO.

For now, you'll have a problem when you try to pass it into a ColumnConfig or the like, just cast to raw ValueProvider for the time being. The fix will either be to correct those generics so a raw cast is not necessary, or find a way to make generic PropertyAccess subtypes be generated correctly.

16 Jan 2012, 5:09 AM
Hi Colin, thanks for your answer.
Doing more testing on GXT 3.0 I found other errors that maybe related, not sure to this issue.

I have this class :

public class OnFlyTypeComboView<T extends TypeDTO> extends ListView<T,T> {
public interface Bundle extends ClientBundle {
TypeStyle css();

public interface TypeStyle extends CssResource {
String item();

public interface OnFlyTypeTemplate<T> extends XTemplates {
@XTemplate("<div class='{style.item}'><h3>{model.abbreviation}</h3>model.name</div>")
SafeHtml render(T model, TypeStyle style);

protected SafeHtml format(T model) {
return this.template.render(model, bundle.css());

When I run this I received the error:

[DEBUG] [arballonwebtest] - Rebinding com.arballon.web.core.client.field.types.OnFlyTypeComboView.OnFlyTypeTemplate
[DEBUG] [arballonwebtest] - Invoking generator com.sencha.gxt.core.rebind.XTemplatesGenerator
[DEBUG] [arballonwebtest] - Creating XTemplate method render
[DEBUG] [arballonwebtest] - Running class com.sencha.gxt.data.rebind.ValueProviderCreator
[WARN] [arballonwebtest] - Method getAbbreviation could not be found
[ERROR] [arballonwebtest] - No getter can be found, unable to proceed

This happens when it builds an instance of:

OnFlyTypeComboView<MessureUnitDTO> view=new OnFlyTypeComboView<MessureUnitDTO>();

Im really concern about this, it seems that inheritance is an issue or maybe Parameters and inheritance not sure, but will be very difficult for us to use the way is working at the beta.


Colin Alworth
16 Jan 2012, 5:59 AM
The @XTemplate annotation cannot be used on a generic method at this time, and there is no plan to support this: what does it mean to ask for (T extends TypeDTO).abbreviation? Either you mean TypeDTO.abbreviation, in which case the generics are useless, or you mean that every single possible T has a getAbbreviation() method, but TypeDTO doesnt - and how is any real java supposed to be written that supports that?

The only possible case I can come up with where the method itself should support generics is when you extend the template sometimes, but want a fallback as well. In that case, take the three extra lines to declare another interface:

// widget requires an instance of SomeTemplate
public interface SomeTemplate<T extends SomeType>{
SafeHtml template(T instance);

//default interface
public interface DefaultTemplate extends SomeTemplate<SomeType> {
SafeHtml template(SomeType instance);
//widget code
private SomeTemplate t = GWT.create(DefaultTemplate.class);
//that would not be a safe cast normally, but we get away with it here because of GWT.create

//overridding code
interface NewTemplate extends SomeTemplate<SomeTypeSubClass> {
@XTemplate{"using subclass methods")
SafeHtml template(SomeTypeSubClass);
SomeWidget<SomeTypeSubClass> w = new SomeWidget<SomeTypeSubClass>(GWT.create(NewTemplate.class));

If you can come up with any usecase where it makes sense to ask for T.property, we can revisit this.

16 Jan 2012, 11:00 AM
Yes Colin you are right. I don't need to use the T parameter in this case.
I can reference directlty TypeDTO class in the method of the OnFlyTypeTemplate and define this interface without any parameter, because as you mentioned I was refering to TypeDTO.abbreviation

I change my code tested and it works fine.
The reason I wrote it wrong was because I misunderstand the behavoir of the XTemplate interface and I had plans to subclassify, now I see that I can't.

Thanks for your help!

Colin Alworth
16 Jan 2012, 12:22 PM
As in my example, you still can extend the template later (with a little creative casting), and even without T, you can subclass your model and pass it into the template.

16 Jan 2012, 12:54 PM
It's ok I don't need it from now Colin.
Actually I'm more concern about the first issue that the second, now that I found my mistake.;)