You have to instanciate your ValueListBox with the second parameter
"ProvidesKey" and implement the getKey() method.
Your code should look something like this :
@UiField(provided = true)
public ValueListBox<IMySubProxy> listBox = new
ValueListBox<IMySubProxy>(new ProxyRenderer<IMySubProxy>(null) {
@Override
public String render(IMySubProxy object) {
return object == null ? null : object.getName();
}
}, new SimpleKeyProvider<IMySubProxy>() {
@Override
public Object getKey(IMySubProxy item) {
return item == null ? null : object.getName();
}
});
On 12 avr, 18:59, Christien Lomax <
thecatwhispe...@gmail.com> wrote:
> I can't seem to find a single example of how to integrate a ListBox or
> ValueListBox with an Editor.
>
> I've put an VLB in my editor, and it sets the value, but if I add any values
> to the VLB, it just tacks them onto the end (So I'll have two of the same
> items in the list, one added by the editor, and the other added by me when I
> add the VLB's acceptableValues.)
>
> A UI has a list of "MyProxy" (which is a Thing), when a user clicks on a
> "thing", the editor is shown (via the workflow). The
> item is retrieved and shown in the editor. The editor needs to load the
> list of MySubProxy (SubThings) and set the selected item as provided by the
> MyProxy (Thing) object.
>
> Instead, the edit correctly sets all teh values, but appends the acceptable
> values (List<MySubProxy>) to the list which already contains the value set
> by the MyProxy object.
>
> Does anyone have an example of this working that they can share, or can you
> point out what I'm doing wrong (code below)?
>
> eg: (obviously, I've changes the names of the things to protect my
> organization's model.. and added "..." where code exists but is not needed
> for the example)
>
> *MyEditor.ui.xml*
> <ui:UiBinder ...>
> <g:TextBox ui:Field="name"/>
> <g:ValueListBox ui:field="mylist"/>
> </ui:UiBinder>
>
> *MyEditor.java*
> public class MyEditor extends Composite implements Editor<IMyProxy>
> {
> interface Binder extends UiBinder<Widget, MyEditor>
> {
> }
>
> @UiField
> public TextBox name;
> @UiField(provided=true)
> public ValueListBox<IMySubProxy> listBox = new ValueListBox<IMySubProxy>(
> new ProxyRenderer<IMySubProxy>(null)
> {
> @Override
> public String render(IMySubProxy object)
> {
> return object == null ? null : object.getName();
> }
> });
>
> public MyEditor ()
> {
> initWidget(GWT.<Binder> create(Binder.class).createAndBindUi(this));
> MyApp.getRequestFactory().myRequest().listThings(0, 10).fire(new
> Receiver<List<IMySubProxy>>()
> {
> @Override
> public void onSuccess(List<IMySubProxy> response)
> {
> listBox.setAcceptableValues(response);
> }
> });
> }
>
> }
>
> *IMyProxy.java*
> @ProxyFor(value = Thing.class, locator = MyThingGwtAdapter.class)
> public interface IMyProxy extends EntityProxy
> {
> abstract Long getKey();
> abstract String getName();
> abstract IMySubProxy getSubThing();
>
> }
>
> *IMySubProxy.java*
> @ProxyFor(value = SubThing.class, locator = MySubThingGwtAdapter.class)
> public interface IMySubProxy extends EntityProxy
> {
> abstract Long getKey();
> abstract String getName();
>
> }
>
> *MyWorkflow.java*
> *MyWorkflow.ui.xml*