File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes setting default value for a combobox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "setting default value for a combobox" Watch "setting default value for a combobox" New topic
Author

setting default value for a combobox

ram an
Greenhorn

Joined: Feb 12, 2009
Posts: 10
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
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
after loading country list from the database just set countryid="Tokyo" in your backing bean
Rahul Santha
Greenhorn

Joined: Apr 17, 2008
Posts: 12
<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.


Thanks!<br />Rahul, IOWA
ram an
Greenhorn

Joined: Feb 12, 2009
Posts: 10
hey thanks fr all..i got it working...
Haritha Divi
Greenhorn

Joined: Mar 04, 2009
Posts: 1
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: setting default value for a combobox