Editor with ListBox in UiBinder

1,950 views
Skip to first unread message

Ido

unread,
Feb 13, 2011, 7:57:17 AM2/13/11
to google-we...@googlegroups.com
Hi,

Does anyone has a live example of how to use ListBox in an Editor using UiBinder?
I couldn't find anything in the documentation nor in this group.

For now, I can only create Editor with value boxes. The problem is that I need ListBoxes (later to display enum values) and radio button groups.
I hope some of you are familiar with such widgets in editors, any tip will be welcome.

Thanks a lot in advanced,
Ido





Thomas Broyer

unread,
Feb 13, 2011, 9:05:34 AM2/13/11
to google-we...@googlegroups.com
The easiest is to use a ValueListBox instead of ListBox.

Ido

unread,
Feb 13, 2011, 9:39:19 AM2/13/11
to google-we...@googlegroups.com
Don't know how I've missed it!

Is there also an easy solution for radio buttons group?  If not I don't mind to use the ValueListBox instead, only for now...

Thanks a lot Thomas,
Ido

Thomas Broyer

unread,
Feb 13, 2011, 10:22:34 AM2/13/11
to google-we...@googlegroups.com


On Sunday, February 13, 2011 3:39:19 PM UTC+1, Ido wrote:
Don't know how I've missed it!

Is there also an easy solution for radio buttons group?

I guess you could use a ValuePicker with a Cell that renders a radio button. 

George Moschovitis

unread,
Mar 1, 2011, 7:35:02 AM3/1/11
to google-we...@googlegroups.com
Is there a full example of using ValueListBox available?

I have a simple Article/Category model and would like to implement a ValueListBox editor for the article category.
I am using an extension of ProxyRenderer but I am not sure how to construct the CategoryProxy, etc to make this work.

A full example would be extremely helpful.

thanks in advance,
-g.



Ido

unread,
Mar 1, 2011, 7:52:30 AM3/1/11
to google-we...@googlegroups.com
I'm not sure about your Article/Category model and the extension of ProxyRenderer but here is how I use ValueListBox in my editors:

// Defining a ValueListBox which holds country name in my pojo
@UiField(provided = true)
ValueListBox<String> country;

// Creating the ValueListBox
country = new ValueListBox<String>(new Renderer<String>()
{
@Override
public String render(String object)
{
return object;
}

@Override
public void render(String object, Appendable appendable) throws IOException
{
}
});

// Adding values to the ValueListBox
country.setAcceptableValues(/*list of Strings*/);

This example works fine for me..

George Moschovitis

unread,
Mar 1, 2011, 1:25:59 PM3/1/11
to google-we...@googlegroups.com
This is a simple example with Strings, I need an example with a Proxy, ie ValueListBox<MyProxy>
I am not sure which methods the Proxy, Entity, Service etc should have.

I got saving (create) working, but when I reload (edit) the parent editor (ArticleEditor) the ValuListBox editor does not show the correct
CategoryProxy.
 
-g.

Thomas Broyer

unread,
Mar 1, 2011, 3:27:50 PM3/1/11
to google-we...@googlegroups.com
Did you gave your ValueListBox an EntityProxyKeyProvider as ProvidesKey? otherwise it will use equals() to compare the proxy from the property you're editing and the ones in the ValueListBox.

George Moschovitis

unread,
Mar 2, 2011, 4:05:56 AM3/2/11
to google-we...@googlegroups.com
Eh? can you elaborate on this?

thanks for the help!
-g.

Drew Spencer

unread,
Sep 4, 2012, 7:32:37 AM9/4/12
to google-we...@googlegroups.com
Did you guys get anywhere with this? I'm learning the Editor Framework and my ValueListBox only contains the actual value - how do I make it so that I populate the list with a predefined set of values, and select the actual value as selected? I'm using GWTP.

My code for my UiFactory:

        @UiFactory
@Ignore
ValueListBox<String> stateInit()
{
return new ValueListBox<String>(new Renderer<String>()
{
@Override
public String render(String object)
{
return object;
}
@Override
public void render(String object, Appendable appendable) throws IOException
{
if(object != null)
{
                                        // NEED SOME LOGIC HERE?
appendable.append(object);
}
}
});
}

Cheers,

Drew

Ümit Seren

unread,
Sep 5, 2012, 4:02:10 AM9/5/12
to google-we...@googlegroups.com
valueBox.setAcceptableValues(List<EntityProxy> values);

Drew Spencer

unread,
Sep 5, 2012, 6:54:52 AM9/5/12
to google-we...@googlegroups.com
Hi,

I created a list of the 4 strings, called setAcceptableValues(list) in the connstructor, but now I get the 4 values in the list, plus a null entry. What am I doing wrong? This is my AddressEditor.java:

public class AddressEditor extends Composite implements Editor<Address>
{
private static AddressEditorUiBinder uiBinder = GWT.create(AddressEditorUiBinder.class);
interface AddressEditorUiBinder extends UiBinder<Widget, AddressEditor>
{
}
@UiField
TextBox street;
@UiField
TextBox city;
@UiField
TextBox zip;
@UiField
ValueListBox<String> state;
public AddressEditor()
{
initWidget(uiBinder.createAndBindUi(this));
List<String> states = new ArrayList<String>();
states.add("Scotland");
states.add("England");
states.add("Wales");
states.add("Ireland");
state.setAcceptableValues(states);
}
@UiFactory
@Ignore
ValueListBox<String> stateInit()
{
return new ValueListBox<String>(new Renderer<String>()
{
@Override
public String render(String object)
{
return object;
}
@Override
public void render(String object, Appendable appendable) throws IOException
{
if(object != null)
{
appendable.append(object);
}
}
});
}
}


I suspect the first render function is being called, but I can't do a null check on it as it needs a return value.

Thanks

Thomas Broyer

unread,
Sep 5, 2012, 10:11:30 AM9/5/12
to google-we...@googlegroups.com


On Wednesday, September 5, 2012 12:54:52 PM UTC+2, Drew Spencer wrote:
Hi,

I created a list of the 4 strings, called setAcceptableValues(list) in the connstructor, but now I get the 4 values in the list, plus a null entry. What am I doing wrong?

If there's a 'null' entry that you didn't add in the "acceptable values", then it means setValue(null) was called, i.e. you're editing an Address whose getState() returns 'null'.

Drew Spencer

unread,
Sep 5, 2012, 10:33:13 AM9/5/12
to google-we...@googlegroups.com
Hi Thomas, I was hoping you would see this as I've read your blog posts and answers on SO but am still confused.

This is the first time I've used the Editor framework The address is a sub-editor of Person, which is simply being created on an onBind() of a test presenter I'm using:

PersonPresenter:

@Override
protected void onBind()
{
super.onBind();
// this would be replaced with a call to datastore
Address address = new Address("447a Archway Road", "Highgate", "N6 4HT", "Scotland"); // Scotland is the state
Person person = new Person("1", "Drew", "Spencer", address);
getView().edit(person);
}

Surely if I am instantiating the object this way then the state will return with the value? I tried setting the acceptable values before the initwidget call but that gives a nullpointerexception.

Am totally confused :/

Jens

unread,
Sep 5, 2012, 11:18:24 AM9/5/12
to google-we...@googlegroups.com
Currently ValueListBox automatically adds a "null" value even if its not in the list of acceptable values. You don't have to call ValueListBox.setValue(null) yourself. That's because setAcceptableValues() calls updateListBox() which adds the currently selected value to the ListBox if its not in the set of acceptable values. By default "null" is the selected value.

This behavior has been changed in http://gwt-code-reviews.appspot.com/1619803/ but its not yet committed.

Currently if you want a ValueListBox without a null value you would do:

ValueListBox valueListBox = new ...
valueListBox.setValue(<any value that is in acceptable values>);
valueListBox.setAcceptableValues(<acceptable values without null>);


-- J.

Drew Spencer

unread,
Sep 13, 2012, 5:38:40 AM9/13/12
to google-we...@googlegroups.com
Thanks for the reply. So, I guess I will wait until 2.5 comes out and see whether there are any changes made in the near future.

I can live with a null value there for a while as it's only in development stage.

You guys are great.

Drew
Reply all
Reply to author
Forward
0 new messages