Requestfactory and CellBrowser Context Problem

65 views
Skip to first unread message

jmbz84

unread,
Mar 14, 2012, 9:47:55 PM3/14/12
to Google Web Toolkit
Hello,

I'm trying to use gwt CellBrowser and RequestFactory to show some
stored data as Cells in the cellbrowser. But I can't do it because of
the context of requestfactory.


Any Ideas ?

class CustomTreeModel implements TreeViewModel {
{
...
..
...

List<ComposerProxy> composerproxy = new ArrayList<ComposerProxy>();

private void setComposer() {
testRequestFactory = GWT.create(TestRequestFactory.class);
testRequestFactory.initialize(new SimpleEventBus());

request.getQuery("select a from Composer a").fire(
new Receiver<List<ComposerProxy>>() {

@Override
public void onSuccess(List<ComposerProxy> arg0) {
//Here Is my problem, How
can I transfer the value of arg0 to composerproxy in order to use it
on my CellBrowser ()
// Tried with a for() to
insert each ComposerProxy individually and with a separate method
insertcomposerproxy(arg0) but didnt work
composerproxy=arg0;

}
});

}

}

public <T> NodeInfo<?> getNodeInfo(T value) {

if (value == null) {

setComposer();

// LEVEL 0.
// We passed null as the root value. Return the composers.
// Create a data provider that contains the list of composers.

//HERE IS MY PROBLEM. The composerproxy
variable is empty.

ListDataProvider<ComposerProxy> dataProvider = new
ListDataProvider<ComposerProxy>(
composerproxy);



// Create a cell to display a composer.
Cell<ComposerProxy> cell = new AbstractCell<ComposerProxy>() {
@Override
public void render(Context context, ComposerProxy value,
SafeHtmlBuilder sb) {
if (value != null) {
sb.appendEscaped(value.getName());
}
}
};
// Return a node info that pairs the data provider and the cell.
return new DefaultNodeInfo<ComposerProxy>(dataProvider, cell);
}
......
.....
.....
.....

}



PD: The getQuery() function works fine and the arg0 variable has data.

Thomas Broyer

unread,
Mar 15, 2012, 6:23:20 AM3/15/12
to google-we...@googlegroups.com
Try using an AsyncDataProvider instead of ListDataProvider.

(also: embrace asynchrony!)

jmbz84

unread,
Mar 15, 2012, 4:52:25 PM3/15/12
to Google Web Toolkit
Thanks Thomas that worked :).

I have another question when the items how in the CellBrowser the text
"Show more" and "Show less" appears in the bottom. How can I disable
it???

Here is the code :


//How to call it
ComposerDataProvider dataProvider = new
ComposerDataProvider(testRequestFactory);


//The actual Class
public class ComposerDataProvider extends
AsyncDataProvider<ComposerProxy> {
private TestRequestFactory rf;

public ComposerDataProvider(TestRequestFactory requestFactory) {
this.rf = requestFactory;
}

@Override
protected void onRangeChanged(HasData<ComposerProxy> display) {

getData();
}

private void getData() {

ComposerRequest request = rf.getComposerRequest();

request.getQuery("select a from Composer a").fire(
new Receiver<List<ComposerProxy>>() {
@Override
public void onSuccess(List<ComposerProxy> arg0) {
updateRowData(0, arg0);
}
});
}
}

jmbz84

unread,
Mar 15, 2012, 4:58:53 PM3/15/12
to Google Web Toolkit
Found it! updateRowCount(arg0.size(), true); was missing.......

public void onSuccess(List<ComposerProxy> arg0) {
updateRowCount(arg0.size(), true);
updateRowData(0, arg0);
Reply all
Reply to author
Forward
0 new messages