Driver Best Practices with CheckBox and RadioButtons

1,207 views
Skip to first unread message

jefe

unread,
Nov 2, 2010, 12:00:35 AM11/2/10
to Google Web Toolkit
All,

After reviewing the GWT 2.1 Editor/Driver features I've found uses
fields like TextBox or DoubleBox but nothing pertaining to concepts
such as CheckBox or RadioButton. Are there any specific best practices
for providing binding between a bean and a group of radio buttons or a
checkbox?

Any insight would be appreciated.

Thanks,
Jeff

Thomas Broyer

unread,
Nov 2, 2010, 2:37:33 PM11/2/10
to Google Web Toolkit
A CheckBox is an IsEditor<LeafValueEditor<Boolean>> so you can use it
to edit boolean values the same as a TextBox for String values.

For more complex use cases (list of checkboxes to edit a list of
values, or a radio button group to edit a single value (insteaf of,
say, a ValueListBox)), you'd have to make your own editor.
For radio buttons, you might be able to use a ValuePicker passing a
CellList with a RadioButtonCell (you'd have to make your own Cell,
based on CheckBoxCell, or use CheckBoxCell if rendering as a checbox
rather than radio button doesn't bother you)

will0

unread,
Nov 9, 2010, 1:08:02 PM11/9/10
to Google Web Toolkit


On Nov 2, 4:00 am, jefe <jeffrey.burn...@gmail.com> wrote:
> All,
>
> After reviewing the GWT 2.1 Editor/Driverfeatures I've found uses
> fields like TextBox or DoubleBox but nothing pertaining to concepts
> such as CheckBox or RadioButton. Are there any specific best practices
> for providing binding between a bean and a group of radio buttons or a
> checkbox?
>
> Any insight would be appreciated.
>
> Thanks,
> Jeff


Hi Jeff

I can't be authoritative on best practice, however I've got a few
widgets that wrap GWT widgets (TextBox and ListBox) which edit simple
values such as Strings and Integers.
I just make them implement LeafValueEditor<T> and they work in the
same way as a GWT widget does with the editor framework.

For example :
"""
public class CharField extends FormRow implements
LeafValueEditor<String> {
......
@Override
public String getValue() {
return tb.getValue();
}

@Override
public void setValue(String value) {
setValue(value, false);
}
}
"""

Cheers

Will

Geraldo Lopes

unread,
Nov 10, 2010, 8:42:42 AM11/10/10
to Google Web Toolkit
will0,

Thanks for the code piece. I used it to make an extension of ListBox.

public class MyListBox extends ListBox implements
LeafValueEditor<String> {

@Override
public void setValue(String value) {
if (value == null) {
setSelectedIndex(-1);
return;
}

for (int i=0;i<getItemCount();i++) {
if (getValue(i).equals(value)) {
setSelectedIndex(i);
return;
}
}

for (int i=0;i<getItemCount();i++) {
if (getItemText(i).equals(value)) {
setSelectedIndex(i);
return;
}
}

}

@Override
public String getValue() {
if (getSelectedIndex() == -1)
return null;

if (getItemText(getSelectedIndex()).trim().equals(""))
return null;

String value = getValue(getSelectedIndex());

if (value != null) {
return value;
}

return getItemText(getSelectedIndex());
}

}



On 9 nov, 16:08, will0 <willtemper...@gmail.com> wrote:
> On Nov 2, 4:00 am, jefe <jeffrey.burn...@gmail.com> wrote:
>
> > All,
>
> > After reviewing the GWT 2.1Editor/Driverfeatures I've found uses

Thomas Broyer

unread,
Nov 11, 2010, 7:35:13 AM11/11/10
to Google Web Toolkit


On 10 nov, 14:42, Geraldo Lopes <geraldo...@gmail.com> wrote:
> will0,
>
> Thanks for the code piece. I used it to make an extension of ListBox.
>
> public class MyListBox extends ListBox implements
> LeafValueEditor<String> {

I think you basically reinvented ValueListBox:
http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/ui/ValueListBox.html

(and if you want to use a CellList, you can use ValuePicker)

Geraldo Lopes

unread,
Nov 11, 2010, 7:50:10 AM11/11/10
to Google Web Toolkit
Thomas,

Thanks for the information. That was my 1st shoot with Editor
framework.

Regards,

Geraldo

On 11 nov, 10:35, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 10 nov, 14:42, Geraldo Lopes <geraldo...@gmail.com> wrote:
>
> > will0,
>
> > Thanks for the code piece. I used it to make an extension ofListBox.
>
> > public class MyListBox extendsListBoximplements
> > LeafValueEditor<String> {
>
> I think you basically reinvented ValueListBox:http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/g...

Jerome C.

unread,
Nov 12, 2010, 6:40:45 AM11/12/10
to Google Web Toolkit
I'm confused with this ValueListBox.

I don't understand differences between ListBox and ValueListBox.

Moreover, why ListBox is not editable directly with Editor mechanism ?

I've got a ListBox working with uibinder but I can't make it work with
Editor (because it does not implement Editor).
I can't make ValueListBox work with uibinder.

How can we bind ValueListBox with g:item in uibinder ?

Lot of questions but the new GWT editor feature is not very clear in
documentation...



On 11 nov, 13:50, Geraldo Lopes <geraldo...@gmail.com> wrote:
> Thomas,
>
> Thanks for the information. That was my 1st shoot with Editor
> framework.
>
> Regards,
>
> Geraldo
>
> On 11 nov, 10:35, Thomas Broyer <t.bro...@gmail.com> wrote:
>
>
>
>
>
>
>
> > On 10 nov, 14:42, Geraldo Lopes <geraldo...@gmail.com> wrote:
>
> > > will0,
>
> > > Thanks for the code piece. I used it to make an extension ofListBox.
>
> > > public class MyListBox extendsListBoximplements
> > > LeafValueEditor<String> {
>
> > I think you basically reinventedValueListBox:http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/g...

Craigo

unread,
Nov 14, 2010, 6:51:16 PM11/14/10
to Google Web Toolkit
I'm also confused as to why ListBox wasn't updated to work with the
Editor.

I can't see how ValueListBox would ever be able to take g:item, or
anything else, as it doesn't have a zero arg constructor, so it needs
@UiField(provided=true).

The only way I've managed to give it values is in code, by calling
setAcceptableValues.


On Nov 12, 10:40 pm, "Jerome C." <jerome.ca...@gmail.com> wrote:
> I'm confused with thisValueListBox.
>
> I don't understand differences between ListBox andValueListBox.
>
> Moreover, why ListBox is not editable directly with Editor mechanism ?
>
> I've got a ListBox working with uibinder but I can't make it work with
> Editor (because it does not implement Editor).
> I can't makeValueListBoxwork with uibinder.
>
> How can we bindValueListBoxwith g:item in uibinder ?

Craigo

unread,
Nov 14, 2010, 7:16:56 PM11/14/10
to Google Web Toolkit
FYI: I'm using Geraldo solution above (minus the @Override
statements), as it is much easier to integrate it with the UIBinder
then the ValueListBox. Thanks Geraldo!
Reply all
Reply to author
Forward
0 new messages