-
2 Feb 2012 10:28 AM #1
Answered: ValueProvider+RequestFactory - how to access properties of nested object?
Answered: ValueProvider+RequestFactory - how to access properties of nested object?
Hi everybody,
i'm trying to figure out how to display properties from related object in a grid.
Let's say I have entity object called "Song",that is relating to "Genre" object.
Now,what I want to achieve is to display list of "Song" objects on grid,but also include some of the details from related "Genre" object.
From what I read on GXT 3.0, valueProviders should be able to do that, but I haven't found out how to do it.
So far,I have managed to do this without problem:
interface SongProxyProperties extends PropertyAccess<SongProxy> {
ModelKeyProvider<SongProxy> id();
ValueProvider<SongProxy, String> artist();
.
.
.
ValueProvider<GenreProxy, String> genre(); ?????????
}
Can anyone help me with this?
Tnx,
Igor
-
Best Answer Posted by IgyBoy
Never mind, figured it out - have read about GWT Editor framework a bit...
-
4 Feb 2012 1:31 AM #2
Never mind, figured it out - have read about GWT Editor framework a bit...
Last edited by IgyBoy; 4 Feb 2012 at 5:31 AM. Reason: Figured it out.
-
22 Feb 2012 4:10 AM #3
How did you do it finally?
How did you do it finally?
Hey Igor,
Could you tell us how you did it? We are also looking for the same thing, but reading GWT Editor docs did not make us any wiser
...
Thanks,
Koen
-
22 Feb 2012 4:48 AM #4
Hi koenjan,
the "@Path" annotation is what you are looking for:
From the GWT docs:
"The @Path annotation may be used on the field or accessor method to specify a dotted property path or to bypass the implicit naming convention. For example:
class PersonEditor implements Editor<Person> {
// Corresponds to person.getManager().getName()
@Path("manager.name");
Label managerName;
}
So, in the example that I had above:
interface SongProxyProperties extends PropertyAccess<SongProxy> {
ModelKeyProvider<SongProxy> id();
ValueProvider<SongProxy, String> artist();
@Path("genre.genreName")
ValueProvider<SongProxy, String> songGenre();
}
The @Path("genre.genreName") is basically saying: take "genreName" property from related "genre" object, and expose it as "songGenre" in SongProxyProperties interface.
Hope this was helpfull.
Cheers,
Igor
-
22 Feb 2012 6:28 AM #5
Thank you for your response...
In fact, we already tried the @Path annotation, but somehow we got NullPointerExceptions...
after some debugging, we found that to be able to use
that instead ofCode:@Path("type.name") ValueProvider<DetailProxy, String> typeName;
which did not include the <DetailTypeProxy> inside the <DetailProxy>,Code:detailRequest.get().find(requestId).fire(receiver<DetailProxy>)
we had to do
maybe this is useful for others...Code:detailRequest.get().find(requestId).with("type").fire(receiver<DetailProxy>)
-
19 Oct 2012 10:51 AM #6
I am having a very similar issue. I am using RequestFactory with Hibernate to populate a Sencha grid with a paging toolbar. By using the path annotation I was able to successfully populate the grid with data. I then tried to implement the paging toolbar which requires the use of RequestFactoryProxy and am now receiving a NullPointerException for the Columns in the grid that access nested objects. It seems that the use of the with() method within the context of RequestFactoryProxy doesn't work as expected.
-
4 Dec 2012 9:04 PM #7
How do we prevent from throwing null pointer exception of ValueProvider
-
5 Dec 2012 4:17 AM #8
@Adam.Elkins:
Check out on this thread:
http://www.sencha.com/forum/showthre...related-entity
I had the same problem,so it might be helpful to you.
-
5 Dec 2012 7:16 AM #9
Let say we have a Person, and Person.getAddress() returns an Address object, and Address.getCity() returns a String city that person lives in. We might use this PropertyAccess:
In this case, we'll be able to use that ValueProvider to get and set the city of the address of the person as if we were writing these lines of code:Code:interface PersonProperties extends PropertyAccess<Person> { @Path("address.city") ValueProvider<Person, String> city(); }
But what happens if the address is null? It can't magically know that you don't want that to be null, that you intend for it to have a non-null value, and it can't create a new Address object for you - in that case, what should getCity do? Even if we rebuild that (and this doesn't make sense to me) to return null, what can setCity do when the user types in a value, for example, in a grid?Code:person.getAddress().getCity() person.getAddress().setCity(...)
There is no way for us to create those sub-objects in a consistent way - what if you need a StreetAddress subclass of the abstract Address class? What if Address is a RequestFactory proxy, and thus only an interface? What if you must use a non-default constructor to build Address? Any of these make it hard to generate code that builds your sub-objects for you.
If you want custom behavior in your ValueProvider, built a custom implementation of the interface. PropertyAccess is only for simple generated default behavior.
Code:class PersonWithNullableAddressCityValueProvider implements ValueProvider<Person, String> { public String getValue(Person object) { return object.getAddress() == null ? null : object.getAddress().getCity(); } public void setValue(Person object, String value) { if (person.getAddress() == null) { person.setAddress(new Address()); } person.getAddress().setCity(value); } }
-
5 Dec 2012 8:05 AM #10


Reply With Quote