tags:

views:

104

answers:

2

I am trying to use ListBox with HasValue interface implemented, I got code / idea from the following link and I made the my own list box class

http://turbomanage.wordpress.com/2010/04/01/selectonelistbox-for-use-with-gwtmvp/

Now the problem is I am using @UiTemplate in my Views and I am finding it difficult to cast ListBox to this new ListBox.

My View class code:

// 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 ;
}
A: 

You cannot cast ListBox to SelectOneListBox ("this new ListBox"), because ListBox is not an implementation of SelectOneListBox. Unlsee you have reference to ListBox, but in fact you keep SelectOneListBox in it. However I doubt it, because then your code should work.

Show us some code if you want to help us help you.

amorfis
I am using the SelectOneListBox as given in blog, The ListBox i want to show will have country list in it , i tried to cast it like below but it gives me exception public HasSelectedValue <T> getCountry() { SelectOneListBox<T> sel = new SelectOneListBox<T>(null); sel =(SelectOneListBox<T>) countryListBox; //return (SelectOneListBox<T>) countryListBox; return sel; //return countryListBox ;}
Saket Bansal
Could you please edit your question and put your code there? It is not readable in comment.
amorfis
A: 

Your problem here is that countryListBox is a ListBox and not SelectOneListBox and thats why you cant cast it to a SelectOneListBox.

See this link for how to include custome widgets in UiBinder

pathed
Thanks, this is what i was missing.... new to GWT :-)
Saket Bansal