GWT 2.4를 사용하고 있습니다. 내 onModuleLoad 메서드에서 문자열 id가 주어지면 RootPanel 객체에서 페이지의 기존 버튼에 대한 참조를 얻는 방법은 무엇입니까? 나는 "버튼에 인 RootPanel에서 캐스팅 할 수 없습니다"이GWT : RootPanel에서 버튼에 대한 참조를 얻으려면 어떻게해야합니까?
public void onModuleLoad() {
...
final Button submitButton = (Button) RootPanel.get("submit");
을 시도하지만 컴파일 오류가납니다.
편집 :
내가 고통을 치유 할 반복자를 사용하여 생각하지,하지만 주사위. 다음로드 기본 HTML (ID = "제출"을 버튼을 통지) ...
<div>
<form name="f">
File name: <input type="text" size="25" id="filename" name="filename"
value="" /> <input type="button" id="submit" name="submit"
value="Submit" /> <input type="hidden" name="curId" id="curId"
value="" />
</form>
</div>
<div id="content"></div>
지만는 onModuleLoad에서이 코드는 NullPointerException이 발생합니다 (submitButton ID가 찾을 수 없기 때문에) ...
public void onModuleLoad() {
final Button submitButton = (Button) getWidgetById("submit");
submitButton.addStyleName("submitButton");
...
private Widget getWidgetById(final String id) {
Widget eltToFind = null;
final Iterator<Widget> iter = RootPanel.get().iterator();
while (iter.hasNext()) {
final Widget widget = iter.next();
final Element elt = widget.getElement();
if (elt.getId() != null && elt.getId().equals(id)) {
eltToFind = widget;
break;
} // if
} // while
return eltToFind;
}
감사합니다, - 데이브
순금. - Dave – Dave