带有HasValue和@UiTemplate的GWT列表框

带有HasValue和@UiTemplate的GWT列表框,gwt,gwt-mvp,Gwt,Gwt Mvp,我试图使用ListBox实现HasValue接口,我从下面的链接获得了代码/想法,并创建了我自己的列表框类 现在的问题是我在视图中使用了@UiTemplate,我发现很难将列表框转换到这个新的列表框 我的视图类代码: // defines List Box , so it get attached with UiTemplate @UiField ListBox countryListBox ; //-- this function should get the list box, i c

我试图使用
ListBox
实现
HasValue
接口,我从下面的链接获得了代码/想法,并创建了我自己的列表框类

现在的问题是我在视图中使用了
@UiTemplate
,我发现很难将
列表框
转换到这个新的
列表框

我的视图类代码:

// defines List Box , so it get attached with UiTemplate
 @UiField ListBox countryListBox ;

//-- this function should get the list box, i call this in presenter...
//-- now the problem is i do not know how i take this listbox back as selectOneListBox
 public HasSelectedValue <T> getCountry() {
        // TODO Auto-generated method stub
        //return desTextBox;
        SelectOneListBox<T> sel = new SelectOneListBox<T>(null);
        sel =(SelectOneListBox<T>) countryListBox;
        //return  (SelectOneListBox<T>) countryListBox;
        return sel;
        //return countryListBox ;
}
//定义列表框,因此它将与UiTemplate连接
@UiField ListBox countryListBox;
//--这个函数应该得到列表框,我称之为presenter。。。
//--现在的问题是,我不知道如何将此列表框恢复为selectOneListBox
public HasSelectedValue getCountry(){
//TODO自动生成的方法存根
//返回文本框;
SelectOneListBox sel=新建SelectOneListBox(空);
sel=(SelectOneListBox)countryListBox;
//返回(SelectOneListBox)国家列表框;
返回sel;
//返回国家列表框;
}

您不能将
ListBox
强制转换为
SelectOneListBox
(“这个新的
ListBox
”),因为
ListBox
不是
SelectOneListBox
的实现。除非看到您引用了
ListBox
,但实际上您将
SelectOneListBox
保留在其中。但是我对此表示怀疑,因为这样你的代码就可以工作了


如果您想帮助我们,请向我们显示一些代码。

我正在使用博客中提供的SelectOneListBox,我要显示的列表框中会包含国家/地区列表,我尝试按如下方式转换它,但它给我提供了例外public HasSelectedValue getCountry(){SelectOneListBox sel=新的SelectOneListBox(null);sel=(SelectOneListBox)countryListBox;//return(SelectOneListBox)countryListBox;return sel;//returncountrylistbox;}请编辑您的问题并将代码放在那里好吗?注释中不可读。