I'm trying to get a ValueListBox working with RequestFactory, but
unfortunately I'm stuck.
I am able to fill the ValueListBox with the appropriate values and to
successfully retrieve the selected value in the ValueListBox, but I
can't figure out how to make the correct choice of the ValueListBox
selected.
In my application I have two proxies: PlayerProxy and a TeamProxy. A
Player always belong to one Team. Because there are only a few Teams,
I want to be able to select a team from a ValueListBox while editing a
Player.
The relevant code parts:
- PlayerEdit.ui.xml
....
<g:ValueListBox ui:field="teamSelect" />
....
- PlayerEdit.java
....
@UiField(provided = true)
ValueListBox<TeamProxy> teamSelect = new
ValueListBox<TeamProxy>(new ProxyRenderer<TeamProxy>(null) {
@Override
public String render(TeamProxy team) {
return team == null ? "" : team.getName();
}
}, new EntityProxyKeyProvider<TeamProxy>());
.....
- Code to fill the ValueListBox with AcceptableValues:
....
teamRequest.get().findAll().fire(new Receiver<List<TeamProxy>>() {
@Override
public void onSuccess(List<TeamProxy> teams) {
teamSelect.setAcceptableValues(teams);
}
});
....
- Code to set the selected value of the ValueListBox:
....
view.getTeamSelect().setValue(currentPlayer.getTeam());
....
As mentioned before, the ValueListBox gets populated with the names of
the teams, but when a Player already has a Team assigned, the
PlayerDetail view never shows the correct team selected. I'm also not
sure what the "paths" argument of the ProxyRenderer does. What is this
argument for?
Can anybody help me out?
Thanks in advance!
Because PlayerProxy#getTeam() holds a reference to another proxy (TeamProxy), and PlayerProxy is an EntityProxy, you have to explicitly request the "team" property when retrieving the player from the server. Are you correctly using a .with("team") in your request? Otherwise, getTeam() will simply return 'null', which could explain the behavior you're experiencing.
ProxyRenderer#getPaths() helps in populating the .with() of your requests: when requesting your teams, you don't have to know which properties are used by the ProxyRenderer, you simply ask it, because the ProxyRenderer knows what it needs: getAllTeams().with(myTeamProxyRenderer.getPaths()).fire(...). That way, when you change the way you render your teams and need more or less properties, you don't have to update your requests everywhere: simply update the return value of getPaths() and, provided you always use .with(x.getPaths()) everywhere, it will "just work".
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/6lcNO8QoYNAJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.