Change text of buttonCell in celltable

83 views
Skip to first unread message

Deepak Singh

unread,
Nov 5, 2012, 11:15:28 AM11/5/12
to google-we...@googlegroups.com
Hi,

I have a celltable which has one column as ButtonCell.
I am doing some server side work on click of this button. 
Now, i want that the text should change to 'Loading...' when clicked on this button and should again to its original text after i finish server side work.

The point is to show the user that the click has happened and to wait till work in progress.

col.setFieldUpdater() has nothing to achieve this.

Can you pls give me some solution ...

--
Deepak Singh

Thomas Broyer

unread,
Nov 5, 2012, 12:17:40 PM11/5/12
to google-we...@googlegroups.com
The "correct" handling of that situation would be that the column's getValue can return either the "normal" button text or "Loading…", so that it still "works" in case the table is redrawn midway 'til the server responds.
Once you have that, you only need to trigger a redraw of the raw whenever the value ("normal" text vs. "Loading…") changes.

Deepak Singh

unread,
Nov 5, 2012, 1:52:36 PM11/5/12
to google-we...@googlegroups.com
Hi Thomas,

Could you pls elaborate a bit. My code is as follows

Column<HotelSearchDTO, String> bookCol = new Column<HotelSearchDTO, String>(new ButtonCell()) {

@Override
public String getValue(HotelSearchDTO object) {
return "Normal";
}
}; 
bookCol.setFieldUpdater(new FieldUpdater<HotelSearchDTO, String>() {

@Override
public void update(int index, HotelSearchDTO object, String value) {
// How to return "Loading..." from this place as this is the only place to handle click event.
}
});

Thanks
Deepak


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/AfwGLdy3a6AJ.
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.



--
Deepak Singh

Thomas Broyer

unread,
Nov 6, 2012, 4:07:55 AM11/6/12
to google-we...@googlegroups.com


On Monday, November 5, 2012 7:53:59 PM UTC+1, Deepak Singh wrote:

Let's say you have some object that stores "pending requests". To make things simple, let's use a Set<HotelSearchDTO>:

final Set<HotelSearchDTO> pendingRequests = new HashSet<HotelSearchDTO>();

Column<HotelSearchDTO, String> bookCol = new Column<HotelSearchDTO, String>(new ButtonCell()) {

@Override
public String getValue(HotelSearchDTO object) {
return "Normal";

return pendingRequests.contains(object) ? "Loading…" : "Normal";
 
}
}; 
bookCol.setFieldUpdater(new FieldUpdater<HotelSearchDTO, String>() {

@Override
public void update(int index, HotelSearchDTO object, String value) {
// How to return "Loading..." from this place as this is the only place to handle click event.

if (pendingRequest.add(object)) {
  // remember, add returns 'true' if the obejct wasn't already there; that filters out the case when the user clicks on "Loading…" buttons
  // Now, do the request, and in the callback make sure you remove the HotelSearchDTO from the pendingRequests set and redraw the line
  foo.do(new SomeCallback() {
    …
    void onSuccessOrFailure() {
      pendingRequests.remove(object);
      cellTable.redrawRow(index); // you'd better re-compute the index here, in case the table has changed pending the response from the server
    }
  });
  // finally, redraw the line so the button now says "Loading…"
  cellTable.redrawRow(index);
 
}
});

Deepak Singh

unread,
Nov 6, 2012, 4:05:32 PM11/6/12
to google-we...@googlegroups.com
Hi Thomas,

I did something like that,

boolean normalButtonClicked = false; // class variable   

Column<HotelSearchDTO, String> bookCol = new Column<HotelSearchDTO, String>(new ButtonCell()) {

@Override
public String getValue(HotelSearchDTO object) {
return normalButtonlicked ? "Loading…" : "Normal";;


}
}; 
bookCol.setFieldUpdater(new FieldUpdater<HotelSearchDTO, String>() {

@Override
public void update(int index, HotelSearchDTO object, String value) {
normalButtonClicked = true;
                            // server operation
                             // on server completion { normalButtonClicked = false;}
                        }

But its not working. The text of the button is never changed.


Regards
Deepak


--
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.



--
Deepak Singh
Reply all
Reply to author
Forward
0 new messages