How to retrieve selected value from selectOneMenu?
24,025
Solution 1
You should read those tutorials:
Basically you should select value container for selectOneMenu tag. it means that it should look like:
<h:selectOneMenu value="#{comyon.selectedItem}">
<f:selectItems id="meslek7" value="#{comyon.selectıtem}"/>
</h:selectOneMenu>
and if you need to pass a object not string you should use converter. Look at the links on the top.
Solution 2
Although what you choose in your drop-down list, the item's value will be the frist line
<h:selectOneMenu value="#{meslek}">
So, let's declare a variable with name "meslek" and getter/setter to use the value.
private String meslek;
![emreturka](https://i.stack.imgur.com/cQ39g.png?s=256&g=1)
Author by
emreturka
Updated on July 07, 2022Comments
-
emreturka almost 2 years
I need to get the value which I have selected from a selectOneMenu in JSF. I used an ArrayList and I am holding data in it.
<h:outputText value="Meslek : " /> <h:selectOneMenu value="meslek"> <f:selectItems id="meslek7" value="#{comyon.selectıtem}"/> </h:selectOneMenu>
And this is my bean:
@ManagedBean(name = "comyon") @RequestScoped public class ComponentYonetim { private String ad,soyad,cinsiyet; private String sonuc = ""; private ArrayList<SelectItem> selectıtem = new ArrayList<SelectItem>(); private String donenMeslek = ""; public ComponentYonetim() { selectıtem.add(new SelectItem("Asker")); selectıtem.add(new SelectItem("Mühendis")); selectıtem.add(new SelectItem("Doktor")); selectıtem.add(new SelectItem("Öğrenci")); selectıtem.add(new SelectItem("Serbest meslek")); selectıtem.add(new SelectItem("Polis")); } public void yazdir(){ if(this.ad.isEmpty() || this.soyad.isEmpty()){ sonuc+="Lütfen boşluk bırakmayınız!"; } } //setters and getters... }
It's showing the ArrayList data but I can't get value from there. How can I get the value from this selectOneMenu with javaBean?
-
emreturka almost 11 yearsThansk for your help. Links helped me.