Reputation: 1568
Important edit: I added a depth level to the situation to better reflect my problem.
I have a GXT Grid with a ListStore of a certain type Foo
. Foo
happens to have some important object properties, including one of type Bar
. Type Bar
consists of two object properties: fooFoo
of type FooFoo
and barBar
of type Barbar
. These two can be null
and have a String
property description
.
I want to use the GXT grid's filtering to filter the Foo
object records' by their Bar
value's FooFoo
or BarBar
description.
I tried to add a ValueProvider<Foo, String> barDescription();
to FooProperties
, resulting in:
StringFilter<Foo> barbarFilter = new StringFilter<Foo>(fooProps.barbarDescription());
In which Foo#getBarBarDescription()
is implemented as follows:
public String getBarBarDescription() {
return this.getBar().getBarBar().getDescription();
}
Is there a simple/convenient way to implement this behaviour in GXT? I have not found it.
The implementation I describe above is the one I have tried, but the filters don't show up in the grid at all, no further error messages.
In response to Colin's answer to the previous version of my question, I have tried the following:
@Path("bar.barbar.description")
ValueProvider<Foo, String> barbarDescription();
Hoping for it to call Foo#getBar().getBarBar().getDescription()
. I suspect the possibility for FooFoo and BarBar to be null
may be causing issues.
Upvotes: 0
Views: 1360
Reputation: 18331
If you want to have barDescription()
invoke getBar().getDescription()
on your Foo
objects, then try this:
public interface FooProperties extends PropertyAccess<Foo> {
@Path("bar.description")
ValueProvider<Foo, String> barDescription();
//...
}
The @Path
annotation works the same here as it does in the editor framework - you can use it to specify the path to the property you want access to. This allows you to skip creating a getBarDescription()
method in your own Foo
object.
Another option is to just build your own ValueProvider
implementation. Using PropertyAccess
is a way to ask the compiler to do the work for you, but nothing stops you from doing it yourself. In this case, it might look like this:
public class FooBarDescriptionValueProvider implements ValueProvider<Foo, String> {
public String getValue(Foo object) {
//TOOD consider a object.getBar() null check?
return object.getBar().getDescription();
}
public void setValue(Foo object, String value) {
object.getBar().setDescription(value);
}
public String getPath() {
return "bar.description";
}
}
Note that this is almost exactly what the PropertyAccess generated version will look like, but it allows you to customize the behavior however you want.
Upvotes: 1