views:

136

answers:

1
final Button sendButton = new Button("Send");
sendButton.getElement().setId("button");
RootPanel.get().getElement().appendChild(sendButton.getElement());

NodeList buttonElement = Document.get().getElementsByTagName("button");
if(buttonElement != null && buttonElement.getLength() > 0){
buttonElement.getItem(0).setNodeValue("Changed");
}else{
GWT.log("Can't select button");
}

when i use getElementById(), it is OK, but the getElementsbyTagName() method doesn't work. this means i can't make the RPC service return html string response, and attach event at client. i am a little confused here, how to program in GWT? i mean what should RPC service return to client, BO? if return BO, i need to serialize BO, and create elements to construct the dom tree. it is a bother, so any idea to use template in GWT?

A: 

I'm not sure why you're doing everything using elements, or why you need to find the button at all if you still have a reference to it. Your code could be rewritten as:

final Button sendButton = new Button("Send");
RootPanel.get().add(sendButton);

// presumably some RPC is done here...?
onSuccess() {
  sendButton.setText("Changed");
}

It may be helpful if you gave more detail about what you're trying to accomplish. Also, what is BO?

Jason Hall