I’m creating a grid with a variable number of columns. I’m almost done but only one thing left… I cant access attribute Address (PersonProperties interface). I dont know how to write @Path properly. If anyone has any idea, Please give me advice.
I have this JSON: [ {
"FirstName": "John",
"LastName": "Doe",
"Age": 23,
"Details": [
{
"Address": "Apt R113",
"City": "Boston",
"ZipCode": "30523"
},
{
"Address": "ABC 22",
"City": "Paris",
"ZipCode": "51112"
}
]
}
]
and then PropertyAccess interface:
public interface PersonProperties extends PropertyAccess<PersonDTO> {
ModelKeyProvider<PersonDTO> key();
ValueProvider<PersonDTO, String> FirstName();
ValueProvider<PersonDTO, String> LastName();
ValueProvider<PersonDTO, Integer> Age();
@Path("Details???Address")
ValueProvider<PersonDTO, String> Address();
}
Assuming your PersonDTO object is the object representation of the JSON, I would assume you have an interface model (for using AutoBeans) which looks something like this:
Assuming this maps to the interface model you are using (or closely approximates it), then to answer your question, that
@Pathannotation is used to specify the object attribute names to access a property (not the JSON names). So for single attributes, the path annotation can be used if your PropertyAccess value is not the same as the name of the attribute. In your example, your PersonProperties attributes are capitalized, so you can use something like this:If your Details object was just a single object then you could use notation similar to what you wrote (remember the
@Pathannotation is implicity specifying the getters to use to access the property from the object shim):However the Details values are a little different as your JSON example indicates that the
Detailsvalues are actually a collection ofDetails. As a result your grid won’t know how to display Details because there are multiple Details objects for every PersonDTO object. But I’m guessing that was already clear to you so let’s assume that you are trying to display an address in a given row when certain conditions apply. In a case like that, you can implement your own ValueProvider. For example (dervied from a Sencha example I think):Then where you were using the ValueProvider from your PropertyAccess class you will substitute your own ValueProvider and specify the key to use. For a Column Configuration, you could use this ValueProvider to return the street address when the city is Boston:
Obviously this is just one example but hopefully you get the idea.