combo box element value returns index instead of string value

Hi, when I do “element.getChild(0).getProperty(“value”) the value of that Combo box component was the index of the selected item, not the item string itself. I am wondering how I can get the value of the Combo box component, instead of index.

how about select.getValue()?

I can’t access the components directly. And sorry it’s not a select component but a combo box component. I can only access its value through calling element like this: element.getChild(0) that gets me the combo box component textfield and to retrieve the value I do: element.getChild(0).getProperty(“value”)

Why can’t you access the component directly?

I’m generating the components dynamically based on the user need. At start I don’t know how many combo boxes they will need so I have a button that when they click on makes a combo box appear to satisfy business logic. So since I don’t know how many combo boxes they generated I have to iterate through the elements and get the values. For other components I can get my values but for combo box components I get a number instead of the value of the combo box

I still don’t understand. You can easily store even the lowest common interface in a List and iterate over them and get the proper value by checking that the Component implements HasValue and get the value from there

I place all the combo box in a vertical layout, so what I do is I get the vertical layout element and iterate it’s children which are the combo box like element.getChild(0).children.foreach (c → c.getProperty(“value”)

Even there you can call layout getComponents and check that those have the HasValue interface - there is no need to access the element APi

how do I call layout getComponents? I’m new to vaadin

also not to add complications but the layouts are also generated at demand. So I actually iterate all layouts and for each layout I iterate it’s child combo boxes

Sorry it’s called getChildren and returns a stream and it’s still possible - even with nesting. There has to be some logic that you know an element is a combobox and the same logic has to be applied to check that the returned component is a combobox

I know how to identify the combo boxes but when I call the value it gives me a number

I don’t understand

Please show code :wink: and we go from there

thanks I figured it out

Hi, hope you are doing well.

I am facing the same problem and I am very confused with this situation. Is it possible you share with me how you solved this?

I would like to get the value of the selected item in the combo box instead of the automatically generated integer.

Thank you.
Have a nice day.

Please show us some code you tried and what you wanna archive

I am generating combo boxes on demand (dynamically) inside a form layout.

this.formLayout.getChild(3).getProperty(“value”); -----> this gives me back an integer 1,2,3 etc based on the selected item.
I would like to get the value of the selected item back let’s say “Option One” and not 1.

You have to cast your child to HasValue and get the value from there

.,. and Agapi, just out of curiosity, what IDE are you using to write your Vaadin code?