• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

setting default value for a combobox

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ,
i am new to JSF... the design is i have to add a combo box in the JSP page..the data for the combo box, i have called from the database.. when the page loads up i want the value in the combo box to set to default (eg: country = Tokyo)..but i cant set the value
to default...
the code is
<h:selectOneMenu value="#{requestscope.countryid}">
<f:selectItems value="#{pc_page1.countryid}" />
</h:selectOneMenu>

hw to set the default value whn the page loads up to the country i want in the combo box........the country list is in the database...
using JSF

please help
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
after loading country list from the database just set countryid="Tokyo" in your backing bean
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<h:selectOneMenu id="corporationBI"
value="#{pc_page1.countryId}">

<f:selectItems value="#{pc_page1.countries}" />

Backing Bean
countries = new ArrayList<SelectItem>(10);
new SelectItem("NY", "NY")

When pc_page1.countryId = "NY", it gets selected in the UI.
 
ram an
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks fr all..i got it working...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ram an wrote:hey thanks fr all..i got it working...




Hey, I've got a similar problem, can someone please help.
I need to create two combo boxes one for month and other for year.
The month cpmbo box (drop down) lists the 12 months but needs to display the current month as default and similarly year combo box lists from current year to 2004, defaulting to current year.
I've got two problems here:
1) to get default the month and year values displayed in the respective combo boxes
2) to get the drop down list starting from current year to 2004 displayed in the year combo box

I have coded the the list values as:
ArrayList Month = new ArrayList();
Month.add(new LabelValueBean("Jan", "01")); ---- the value '01' is written to DB
Month.add(new LabelValueBean("Feb", "02"));
Month.add(new LabelValueBean("Mar", "03"));
Month.add(new LabelValueBean("Apr", "04"));
Month.add(new LabelValueBean("May", "05"));
.
.
.
Month.add(new LabelValueBean("Dec", "12"));

ta,
Divi
 
I don't always make ads but when I do they're tiny
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic