CheckboxCell 2 clicks for selection, when using SingleSelectionModel

325 views
Skip to first unread message

bb.f.pav

unread,
Jun 10, 2011, 9:36:32 AM6/10/11
to Google Web Toolkit
Hi,

I have a celltable with several columns, one of them holds CheckboxCell
´s. Additional I use a SingleSelectionModel for that celltable. The
CheckboxCell column should be independent from the
SingleSelectionModel. The user should be able to check more that one
checkbox and select only one row via mouse click or keyboard. That's
why I Instantiate them as follows:

celltable.setSelectionModel(new
SingleSelectionModel<MyDomainObject>());
Column<MyDomainObject, Boolean> selCol = new Column<MyDomainObject,
Boolean>(new CheckboxCell()) {
...
};

selCol.setFieldUpdater(new FieldUpdater<MyDomainObject, Boolean>() {
...
});

celltablekurzansicht.addColumn(selCol, "Select");



I chrome everything works as planned, the user can check several
checkboxes. After a Checkbox is clicked, row is selected, status
changed and setFieldUpdater is called.

In firefox 3.6 - 4.0 and ie7 the user can check several checkboxes,
too, but only after two clicks. After the 1st click the row will only
be selected. Only the 2nd click on a selected row will change the
status and call setFieldUpdater.


I hope someone can bring light into the darkness and help me to
achieve the chrome behaviour in firefox (from 3.6) and ie7, too.


thx in advance!
bb.f.pav

Juan Pablo Gardella

unread,
Jun 10, 2011, 6:37:10 PM6/10/11
to google-we...@googlegroups.com
1)  are you sure the code compile for other browser?

2) I do the same thing without problems:

CheckBoxColumn<MyEntity> seleccionado = new CheckBoxColumn<MyEntity>() {
@Override
public Boolean getValue(MyEntity object) {
return object.isSeleccionado();
}
};
seleccionado.setFieldUpdater(fieldUpdaterForMyEntity());

...

private FieldUpdater<MyEntity , Boolean> fieldUpdaterParaDeclaracion() {

return new FieldUpdater<MyEntity , Boolean>() {
@Override
public void update(int index, MyEntity object,
Boolean value) {
if (value != null ) {
object.setSelected(value.booleanValue());
}

};
};
}

I have a selected var. instance (is transient) for query if the entity is selectable. 

Juan



2011/6/10 bb.f.pav <bb.f...@googlemail.com>

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
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.


Patrick Tucker

unread,
Jun 11, 2011, 12:13:51 PM6/11/11
to Google Web Toolkit
I've noticed the same behavior in IE8 too. It's a tad annoying.

bb.f.pav

unread,
Jun 13, 2011, 2:56:48 PM6/13/11
to Google Web Toolkit
Hi Juan,

1) i'm not yet reached that point. i'm using the stockwatcher examples
as basis for my celltable example and run it via eclipse as web
application
that's my module.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='mysamplegwtohnemaven'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>

<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>

<!-- Specify the app entry point class. -->
<entry-point
class='de.f10rian.mySampleGwtOhneMaven.client.MySampleGwtOhneMaven'/>

<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>

</module>

2) Here is my CellTableExample code. hopefully you'll see my error:

public class CellTableExample extends Composite {

private static CellTableExampleUiBinder uiBinder = GWT
.create(CellTableExampleUiBinder.class);

interface CellTableExampleUiBinder extends
UiBinder<Widget, CellTableExample> {
}

@UiField
CellTable<Person> ct;

List<Long> checkBoxSelectedIds = new ArrayList<Long>();

private final ListDataProvider<Person> dataProvider = new
ListDataProvider<Person>();
private final SingleSelectionModel<Person> singleSelectionModel = new
SingleSelectionModel<Person>();

{
singleSelectionModel.addSelectionChangeHandler(new Handler() {
@Override
public void onSelectionChange(SelectionChangeEvent event) {
GWT.log("getSelectedObject" +
singleSelectionModel.getSelectedObject().toString());
}
});
}

public CellTableExample() {
initWidget(uiBinder.createAndBindUi(this));



// name column
Column<Person, String> nameCol = new Column<Person, String>(
new TextInputCell()){
public String getValue(Person object) {
return object.getName();
}
};

nameCol.setFieldUpdater(new FieldUpdater<Person, String>() {
public void update(int index, Person object, String value) {
object.setName(value);
}
});


// title column
Column<Person, String> forenameCol = new Column<Person, String>(
new TextInputCell()){
public String getValue(Person object) {
return object.getForeName();
}
};

forenameCol.setFieldUpdater(new FieldUpdater<Person, String>() {
public void update(int index, Person object, String value) {
object.setForeName(value);
}
});


/*
* add check column
*/
Column<Person, Boolean> cbCol = new Column<Person, Boolean>(new
CheckboxCell()) {
public Boolean getValue(Person object) {
GWT.log("cbCol.getValue: " + Boolean.FALSE);
return object.isSelected();
}
};

cbCol.setFieldUpdater(new FieldUpdater<Person, Boolean>() {
public void update(int index, Person object, Boolean value) {
GWT.log("cbCol.setValue: " + value);
object.setSelected(value);
}
});


// Add the columns.
ct.addColumn(forenameCol, "Forname");
ct.addColumn(nameCol, "Name");
ct.addColumn(cbCol, "Check");

// Set the width of the table and put the table in fixed width
mode.
ct.setWidth("100%", true);

// Set the width of each column.
ct.setColumnWidth(forenameCol, 200.0, Unit.PX);
ct.setColumnWidth(nameCol, 50.0, Unit.PCT);
ct.setColumnWidth(cbCol, 50.0, Unit.PCT);





ct.setSelectionModel(this.singleSelectionModel);
dataProvider.addDataDisplay(ct);

addData();
}


private void addData() {
List<Person> values = new ArrayList<Person>();

values.add(new Person("Dirk", "Nowitzki", Gender.Male));
values.add(new Person("Dwyane", "Wade", Gender.Male));
values.add(new Person("LeBron", "James", Gender.Male));

dataProvider.setList(values);
}
}


Thx
bb.f.pav


On 11 Jun., 00:37, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> 1)  are you sure the code compile for other browser?
>
> 2) I do the same thing without problems:
>
> CheckBoxColumn<MyEntity> seleccionado = new CheckBoxColumn<MyEntity>() {
> @Override
> public Boolean getValue(MyEntity object) {
> return object.isSeleccionado();}
> };
>
> seleccionado.setFieldUpdater(fieldUpdaterForMyEntity());
>
> ...
>
> private FieldUpdater<MyEntity , Boolean> fieldUpdaterParaDeclaracion() {
>
> return new FieldUpdater<MyEntity , Boolean>() {
> @Override
> public void update(int index, MyEntity object,
> Boolean value) {
> if (value != null ) {
> object.setSelected(value.booleanValue());
>
> }
> };
> };
> }
>
> I have a selected var. instance (is transient) for query if the entity is
> selectable.
>
> Juan
>
> 2011/6/10 bb.f.pav <bb.f....@googlemail.com>

Patrick Tucker

unread,
Jun 13, 2011, 4:42:50 PM6/13/11
to Google Web Toolkit
If you don't need the selection model, try NoSelectionModel.

bb.f.pav

unread,
Jun 14, 2011, 2:40:07 AM6/14/11
to Google Web Toolkit
Hi Patrick,

unfortunately i'll need the single selection model for the purpose of
the project ;)

Thx
bb.f.pav
> > > >CheckboxCellcolumn should be independent from the

Juan Pablo Gardella

unread,
Jun 14, 2011, 7:10:12 AM6/14/11
to google-we...@googlegroups.com
The only difference I see is addSelectionChangeHandler. I don't see an error, sorry

2011/6/14 bb.f.pav <bb.f...@googlemail.com>

bb.f.pav

unread,
Jun 14, 2011, 3:06:44 PM6/14/11
to Google Web Toolkit
Ok, np, Thx you Juan for your patience/ efforts

On 14 Jun., 13:10, Juan Pablo Gardella <gardellajuanpa...@gmail.com>
wrote:
> The only difference I see is addSelectionChangeHandler. I don't see an
> error, sorry
>
> 2011/6/14 bb.f.pav <bb.f....@googlemail.com>

Craig Mitchell

unread,
Aug 16, 2012, 9:01:32 PM8/16/12
to google-we...@googlegroups.com, bb.f...@googlemail.com
I also ran into this problem.  I managed to get around it by extending CheckboxCell to listen for the "click" event, instead of the "change" event.

To do this, in my new class, I just overrode getConsumedEvents:
@Override
public Set<String> getConsumedEvents() {
HashSet<String> result = new HashSet<String>();
result.add("click"); // Listen for the click event
return result;
}

And then overrode onBrowserEvent copying the entire method, but adding the "click" event:
@Override
public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event, ValueUpdater<Boolean> valueUpdater) {
...
if ("click".equals(type) || "change".equals(type) || enterPressed) {
...
}

And it all worked!  I have no idea if what I did will work for all situations, so use it at your own risk.

> > > > > > For more options, visit this group at
> > > > > >http://groups.google.com/group/google-web-toolkit?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
Reply all
Reply to author
Forward
0 new messages