1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    25
    Answers
    2
    Vote Rating
    1
    IgyBoy is on a distinguished road

      0  

    Default 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

  2. Never mind, figured it out - have read about GWT Editor framework a bit...

  3. #2
    Sencha User
    Join Date
    Jul 2011
    Posts
    25
    Answers
    2
    Vote Rating
    1
    IgyBoy is on a distinguished road

      0  

    Default


    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.

  4. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    15
    Vote Rating
    0
    koenjan is on a distinguished road

      0  

    Question 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

  5. #4
    Sencha User
    Join Date
    Jul 2011
    Posts
    25
    Answers
    2
    Vote Rating
    1
    IgyBoy is on a distinguished road

      1  

    Default


    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

  6. #5
    Sencha User
    Join Date
    Dec 2011
    Posts
    15
    Vote Rating
    0
    koenjan is on a distinguished road

      0  

    Default


    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
    Code:
    @Path("type.name")
    ValueProvider<DetailProxy, String> typeName;
    that instead of
    Code:
    detailRequest.get().find(requestId).fire(receiver<DetailProxy>)
    which did not include the <DetailTypeProxy> inside the <DetailProxy>,
    we had to do
    Code:
    detailRequest.get().find(requestId).with("type").fire(receiver<DetailProxy>)
    maybe this is useful for others...

  7. #6
    Sencha Premium Member
    Join Date
    Oct 2012
    Posts
    1
    Vote Rating
    0
    Adam.Elkins is on a distinguished road

      0  

    Default


    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.

  8. #7
    Sencha User
    Join Date
    Aug 2012
    Posts
    42
    Vote Rating
    0
    ramgovind is on a distinguished road

      0  

    Default


    How do we prevent from throwing null pointer exception of ValueProvider

  9. #8
    Sencha User
    Join Date
    Jul 2011
    Posts
    25
    Answers
    2
    Vote Rating
    1
    IgyBoy is on a distinguished road

      0  

    Default


    @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.

  10. #9
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,734
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    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:

    Code:
    interface PersonProperties extends PropertyAccess<Person> {
        @Path("address.city")
        ValueProvider<Person, String> city();
    }
    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:
    person.getAddress().getCity()
    
    person.getAddress().setCity(...)
    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?

    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);
        }
    }

  11. #10
    Sencha User
    Join Date
    Aug 2012
    Posts
    42
    Vote Rating
    0
    ramgovind is on a distinguished road

      0  

    Default


    Cool! Appreciated all your support.