OnChange with ComboBox

321 views
Skip to first unread message

stymie

unread,
Jun 3, 2008, 1:41:23 PM6/3/08
to GWT-Ext Developer Forum
Hi I am having a hard time understanding the listeners with the combo
box,

I have a variable int si=0 which I want to change to the corresponding
selected index of the combobox when the onChange fires.

For example the selectedIndex after the onChange was 3 then my si
variable would be equal to 3

I cannot get this to work.

public void onChange(){
si = myComboBox.getSelectedIndex()
}

I know the code above is wrong but this ext library seems a little
harder to understand than the normal gwt widgets.

Thanks
James

leo_BsAs

unread,
Jun 3, 2008, 2:24:09 PM6/3/08
to GWT-Ext Developer Forum
Hi,
I know it is ugly... but if you want to do the select stuff you have
to keep the value into a global variable every time you fire the
onSelect event of the ComboBox. So... when you fire the onChange event
you can retrieve the value set into the variable.
//global variable and methods...
private int selectedIndex = -1;

//setters and getters
setSelectedIndex & getSelectedIndex

----------------------------------------------------------------------

comboBox.addListener(new ComboBoxListenerAdapter() {
public void onSelect(ComboBox comboBox, Record
record, int index) {
setSelectedIndex(index);
}

public void onChange(Field field, Object
newVal, Object oldVal) {

com.google.gwt.user.client.Window.alert(getSelectedIndex());
}

});


I don't know if exists a better way to do that...

I hope it helps you...

Leo

james tyner

unread,
Jun 4, 2008, 5:09:02 PM6/4/08
to gwt...@googlegroups.com
Hi leo,

That helped alot, at least now I am getting the selectedIndex. It's get's even harder though I was gonna use the selectedIndex to set/reset the store of a datagrid.

I get an error that the store cannot be "reset" once the component(grid) has been rendered. I may just need to go back to the basic GWT components, and hope a good book comes along, as this may be a little over my head.

Thanks for your help :-).

leo_BsAs

unread,
Jun 5, 2008, 9:43:05 AM6/5/08
to GWT-Ext Developer Forum
Hi James...
you're right... we need more documentation...
But the forum is rich in information. I learn gwt-ext from the posts
and the examples (and my english is not so well, so imagine :) ).
It's a matter of persistence... and then you'll find gwt-ext is more
easy, pretty and powerfull than plain gwt. Sanjiv did an excellent job
wrapping extjs, and supporting us... So give it a chance, and you will
not regreat.

By the way... I don't get what you mean with 'reset'. I f you want to
clean the records of the grid, you should only remove all the records
from the grid:
gridStore.removeAll();

if you want to reconfigure the grid: you can call this GridPanel's
method:

reconfigure(Store store, ColumnModel columnModel)


Regards, Leo

On Jun 4, 6:09 pm, "james tyner" <jamesty...@gmail.com> wrote:
> Hi leo,
>
> That helped alot, at least now I am getting the selectedIndex. It's get's
> even harder though I was gonna use the selectedIndex to set/reset the store
> of a datagrid.
>
> I get an error that the store cannot be "reset" once the component(grid) has
> been rendered. I may just need to go back to the basic GWT components, and
> hope a good book comes along, as this may be a little over my head.
>
> Thanks for your help :-).
>

james tyner

unread,
Jun 5, 2008, 10:34:11 AM6/5/08
to gwt...@googlegroups.com
Hi Leo,
 
I'll be sure to browse the forums more.What you have told me seems like exactly what I am needing. I will check it out as soon as I get home.And I agree it is alot prettier than the regular GWT Components.
 
And yes I am very grateful to Sanjiv for all the hard work he has put into this. I was/am a little frustrated because the syntax is a little different, but I'll be hanging out on the forums quite a bit more now that you metntion it.
 
I will let you know how this works out
 
Thanks again
James

 

james tyner

unread,
Jun 5, 2008, 11:15:18 PM6/5/08
to gwt...@googlegroups.com
Wow thanks so much Leo.
Those two solved the grid problem. Now I am feeling quite good seeing that in action :-).

leo_BsAs

unread,
Jun 6, 2008, 8:48:11 AM6/6/08
to GWT-Ext Developer Forum
Cool!



On Jun 6, 12:15 am, "james tyner" <jamesty...@gmail.com> wrote:
> Wow thanks so much Leo.
> Those two solved the grid problem. Now I am feeling quite good seeing that
> in action :-).
>
> On Thu, Jun 5, 2008 at 7:34 AM, james tyner <jamesty...@gmail.com> wrote:
> > Hi Leo,
>
> > I'll be sure to browse the forums more.What you have told me seems like
> > exactly what I am needing. I will check it out as soon as I get home.And I
> > agree it is alot prettier than the regular GWT Components.
>
> > And yes I am very grateful to Sanjiv for all the hard work he has put into
> > this. I was/am a little frustrated because the syntax is a little different,
> > but I'll be hanging out on the forums quite a bit more now that you metntion
> > it.
>
> > I will let you know how this works out
>
> > Thanks again
> > James
>
Reply all
Reply to author
Forward
0 new messages