Making a button fire inside a custom AbstractCell

342 views
Skip to first unread message

Tod Jackson

unread,
Jun 29, 2011, 10:00:39 AM6/29/11
to google-we...@googlegroups.com
Greetings,

First off, the sample I'm describing here is just a trimmed down version of what I'm really going for.  What I'm really trying to do is put a FileUpload widget (gwtupload) inside a Cell so for each row within the table, the user can select one or more files and upload them.  I know one wouldn't typically do what I'm describing here because there are other Cell widgets available that cover it.  I've just trimmed it down to this to try and make sure I understand what I can/can't do in an AbstractCell.  When I saw this behavior as I was trying to use the file upload widget from gwtupload, I simplified it to try and get an idea as to where the issue might be.  The bottom line is it appears as though when creating an AbstractCell that contains a button, I am unable to get the button to fire it's click handler.  Here's some sample code that should demonstrate what I'm trying to do in this narrowed down case:

My AbstractCell:

private static class AbstractButtonCell extends AbstractCell<String> {

@Override

public void render(com.google.gwt.cell.client.Cell.Context context,

final String value, SafeHtmlBuilder sb) {


if (value == null) {

return;

}


VerticalPanel buttonPanel = new VerticalPanel();

Button addLinkButton = new Button("Click " + value);

addLinkButton.addClickHandler(new ClickHandler() {

public void onClick(ClickEvent event) {

Window.alert("You clicked " + value);

}

});

buttonPanel.add(addLinkButton);

sb.appendHtmlConstant(buttonPanel.toString());

}

}


My column that's using the AbstractCell above:


AbstractButtonCell buttonCell = new AbstractButtonCell();

Column<SimilarApplication, String> buttonColumn = 

new Column<SimilarApplication, String> (buttonCell) {

@Override

public String getValue(SimilarApplication object) {

return object.getName();

}

};

 _cellTable.addColumn(buttonColumn, "A Button");

So, when the cell renders, it's got a button in it that says "Click <whatever comes from object.getName()".  However, when I click the button, it's onClick handler doesn't seem to fire.  I've looked through several other posts that discuss AbstractCells but I haven't been able to find one that describes quite what I'm seeing.

Any thoughts or suggestions would be greatly appreciated.  Thanks. 

ashwin....@gmail.com

unread,
Jun 29, 2011, 10:38:20 AM6/29/11
to google-we...@googlegroups.com
 you have not specified the events you want your cell to consume. You will have to add a constructor and specify the events you want  to consume

AbstractButtonCell() {
super(new String[] { "click", "keydown" });
//do rest of the init;
}

~Ashwin


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

Tod Jackson

unread,
Jun 29, 2011, 11:01:54 AM6/29/11
to google-we...@googlegroups.com
Thanks for the reply.  Unfortunately, that doesn't seem to make any difference.  The CellTable I'm working with is in a custom DialogBox, I don't suppose that would make any difference would it?  I know I've had to do a little extra before when using DialogBoxes...perhaps I'll try to eliminate that as a possible culprit.  Thanks again.
Reply all
Reply to author
Forward
0 new messages