-
14 Jan 2012 6:29 AM #1
Unanswered: GXT 3.0 PropertyAccess interface and iinheritance
Unanswered: GXT 3.0 PropertyAccess interface and iinheritance
Hi,
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:
Now in order to implement this I have defined the following interfaces:Code: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; @Mapping("code") public String getMessureUnitCode() { return messureUnitCode; } public void setMessureUnitCode(String messureUnitCode) { this.messureUnitCode = messureUnitCode; } }
But this implementation is not working, when I run this I received the error:Code: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(); @Path("abbreviation") LabelProvider<MessureUnitDTO> label(); } public interface MessureUnitDTOPropertyAccess extends TypeDTOPropertyAccess<MessureUnitDTO> { ValueProvider<MessureUnitDTO, String> messureUnitCode(); @Path("messureUnitCode") ModelKeyProvider<MessureUnitDTO> key(); }
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.Code:[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()
Any help will be appreciated.
Regards.
Daniel
-
15 Jan 2012 9:41 AM #2
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 #3
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 :
When I run this I received the error:Code:public class OnFlyTypeComboView<T extends TypeDTO> extends ListView<T,T> { .... .... public interface Bundle extends ClientBundle { @Source("TypeCombo.css") 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); } @Override protected SafeHtml format(T model) { return this.template.render(model, bundle.css()); } }
This happens when it builds an instance of:Code:[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
I´m 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.Code:OnFlyTypeComboView<MessureUnitDTO> view=new OnFlyTypeComboView<MessureUnitDTO>();
Regards.
Daniel
-
16 Jan 2012 5:59 AM #4
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:
If you can come up with any usecase where it makes sense to ask for T.property, we can revisit this.Code:// widget requires an instance of SomeTemplate public interface SomeTemplate<T extends SomeType>{ SafeHtml template(T instance); } //default interface public interface DefaultTemplate extends SomeTemplate<SomeType> { @XTemplate("...") 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));
-
16 Jan 2012 11:00 AM #5
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!
Daniel
-
16 Jan 2012 12:22 PM #6
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 #7
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.


Reply With Quote