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*
public class MyWorkflow
{
interface Binder extends UiBinder<DialogBox, MyWorkflow>
{
Binder BINDER = GWT.create(Binder.class);
}
interface Driver extends RequestFactoryEditorDriver<IMyProxy, MyEditor>
{
}
public static void register(ECMEventBus eventBus, final MyRequestFactory
requestFactory)
{
eventBus.addHandler(MyEditEvent.TYPE, new MyEditEvent.Handler()
{
public void startEdit(IMyProxy proxy, RequestContext requestContext)
{
new MyWorkflow(requestFactory, proxy).edit(requestContext);
}
});
}
@UiField
DialogBox dialog;
@UiField(provided = true)
MyEditor editor;
private Driver driver;
private IMyProxy proxy;
private final MyRequestFactory requestFactory;
private MyWorkflow(MyRequestFactory requestFactory, IMyProxy proxy)
{
this.requestFactory = requestFactory;
this.proxy = proxy;
editor = new MyEditor();
Binder.BINDER.createAndBindUi(this);
}
@UiHandler("cancel")
void onCancel(ClickEvent event)
{
dialog.hide();
}
@UiHandler("save")
void onSave(ClickEvent event)
{
RequestContext context = driver.flush();
if (driver.hasErrors())
{
dialog.setText("Errors detected locally");
return;
}
context.fire(new Receiver<Void>()
{
...
});
}
private void edit(RequestContext requestContext)
{
driver = GWT.create(Driver.class);
driver.initialize(requestFactory, editor);
if (requestContext == null)
{
fetchAndEdit();
return;
}
driver.edit(proxy, requestContext);
}
private void fetchAndEdit()
{
Request<IMyProxy> fetchRequest = requestFactory.find(proxy.stableId());
fetchRequest.with(driver.getPaths());
fetchRequest.to(new Receiver<IMyProxy>()
{
@Override
public void onSuccess(IMyProxy proxy)
{
MyWorkflow.this.proxy = proxy;
IThingRequest context = requestFactory.thingRequest();
edit(context);
context.saveThing(proxy);
}
}).fire();
}
}
*MyWorkflow.ui.xml*
<ui:UiBinder ...>
<g:DialogBox ui:field="dialog" modal="true">
<g:caption>a caption</g:caption>
<g:HTMLPanel ui:field="contents">
<dt:MyEditor ui:field="editor" />
<div>
<g:Button ui:field="cancel">Cancel</g:Button>
<g:Button ui:field="save">Save</g:Button>
</div>
</g:HTMLPanel>
</g:DialogBox>
</ui:UiBinder>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.