2015-06-25 35 views
0

我有2个smartGWT buttonLayouts包含保存和取消按钮。一个位于UI的顶部,另一个位于底部以方便使用,因此用户无需一直向上/向下滚动以保存/取消表单。smartGWT复制按钮

当用户在任何地方选择保存/取消时,应该禁用所有按钮,直到后台操作完成。

处理这个问题的最佳方法是什么?

如果我这样做:

private Layout buildTopButtonBar() { 
    saveButton = new Button("Save"); 
    saveButton.addClickHandler(...); 
    buttonLayout.addMember(saveButton); 
} 

private Layout buildBottomButtonBar() { 
    saveButton = new Button("Save"); 
    saveButton.addClickHandler(...); 
    buttonLayout.addMember(saveButton); 
} 

saveButton动作(当用户选择保存时,saveButton应禁用)在我的clickHandler事件只在底栏的按钮来进行,但在其他所有后台操作工作。

如果我这样做:显示

saveButton = new Button("Save"); 
saveButton.addClickHandler(...); 
buildTopButtonBar(); // adds saveButton to top bar 
buildBottomButtonBar(); // adds saveButton to bottom bar 

只有底部栏。

我可以创建4个单独的按钮:

topSaveButton = new Button("Save"); 
bottomSaveButton = new Button("Save"); 
... // add all required functionality and clickHandlers 

但这只是感觉罪恶。 我有其他选择吗? 这是smartGWT 4.

回答

1

您不能重用小部件的实例。

Button saveButton = new Button("Save"); // some more code saveButton.addClickHandler(...); buildTopButtonBar(); // adds saveButton to top bar buildBottomButtonBar(); // adds saveButton to bottom bar ;

将不起作用。

Button topSaveButton = new Button("Save"); 
Button bottomSaveButton = new Button("Save"); 
... // add all required functionality and clickHandlers 

将工作。

每个小部件都代表DOM树中的一个节点。您可以通过调用getElement()来访问该节点。再次添加按钮将删除顶部的按钮并将其添加到底部。

如果顶部和底部有保存按钮,则需要两个实例。