Reputation: 1
I have added a button in TabLayoutPanel, and on button click I want to display something, but noting is happening.
Here is sample code for which I was trying :
public void onModuleLoad() {
final TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
//Tab
sendButton.addStyleName("sendButton");
nameField.getElement().setId("PID");
sendButton.getElement().setId("sendButton");
String row = searchAnyTransaction(sendButton, nameField);
tabPanel.add(new HTML(row), "Transaaction Status");
tabPanel.add(new HTML("that"), "[that]");
tabPanel.add(new HTML("the other"), "[the other]");
tabPanel.setPixelSize(500, 400);
final RootLayoutPanel rp = RootLayoutPanel.get();
rp.add(tabPanel);
nameField.setFocus(true);
nameField.selectAll();
//On sendButton click , Clickhandler event should call.
// Create a handler for the sendButton and nameField
sendButton.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
rp.add(sendButton);
//how to add dialog box to display
// Want to display something.
}
});
}
public static String searchAnyTransaction(Button sendbutton, TextBox namefield2){
String htmlForm = ""
+ "<TABLE BORDER=\"2\" ><TR><TH height=\"40\" style=\"width:20%;\"><h3 class=“Search” role=\"tab\" aria-expanded=\"true\" aria-selected=\"true\" tabindex=\"0\">Search</h3></TH>"
+ "<TH height=\"40\" style=\"width:20%;\"><label for=\"fname\">PID:</label></TH><TD height=\"40\" style=\"width:50%;\">" + namefield2
+ "<TD height=\"40\" style=\"width:20%;\">"+ sendbutton +"</TD></TR>"
+ "</TABLE>";
return htmlForm;
}
So I want to display something on button click. Please help me.
Upvotes: 0
Views: 64
Reputation: 5599
Do not build your form as a string.
When you try to concatenate a widget (Button
or TextBox
) with a string, the widget's toString()
method is called.
"string" + sendbutton + "string"
is indeed:
"string" + sendbutton.toString() + "string"
toString()
returns html snippet of the widget, but it will not contain any handlers. That's why the ClickHandler
will never be executed.
Instead, you should build your form using some panel, like Grid
or FlexTable
.
For example:
public static Grid searchAnyTransaction(Button sendbutton, TextBox namefield2){
Grid grid = new Grid(1, 4);
grid.setText(0, 0, "Search");
grid.setText(0, 1, "PID:");
grid.setWidget(0, 2, namefield2);
grid.setWidget(0, 3, sendbutton);
return grid;
}
and add it to the TabPanel like this:
tabPanel.add(searchAnyTransaction(sendButton, nameField), "Transaaction Status");
Upvotes: 2