• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

selected value through select items  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All
I am using h:selectOneMenu and f:selectItem to display a drop down element.In the f:selectItem i am need a element to be preselected how we have do this
<h:selectOneMenu id="xyz" value="#{bean.value}">
<f:selectItems value="#{bean.errMapList}"/> </h:selectOneMenu>

In the list i am adding a selectItem
errMapList.add(new SelectItem(element.getId()+"",element.getName()));

Now i want a value to be selected in the drop down box like selected in html

Regards
Sathish
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


you have bound the value of your selectOneMenu to the "value" attribute of your bean, so set the value in the "value" attribute of your bean that you want to display selected means that when your h:selectOneMenu will render before it your bean's "value" attribute should hold the value that you want to display selected.

It will automtically select that value.
 
nsathishbabu nagarajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes its getting displayed in the order of which i add in the selectItem() but my problem is at the time of loading i want particular value to be selected at the drop down.

for ex: In html option we have property called selected so when the page loaded the particular value will be as default value in the drop down.

Regards
Sathish
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
assign that selected property to the bean's "value" attribute
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!