Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Set the default value in html:select

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:select property="foodType"> <html ption value=" "><fmt:message key="Select a food type"></html ption>
<html ptions collection="foodTypeList" property="keyString" labelProperty="valueString"/>
</html:select>

foodTypeList is a collection that has these elements:-
Entree
Snack
Dessert

How to set Entree as the default?

Thankz in advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <html:select> tag will show the option as "selected" that matches the current value of the ActionForm bean property that is specified in the "property" attribute of the tag.

So, if you want to set a default value, you have to set the ActionForm bean property. In your example, let's suppose that "01" is the key value for "Entree" and that myActionForm is a local variable that refers to your ActionForm bean, the following statement would do the job:

myActionForm.setFoodType("01");


Here are your options:

1- If a particular value is always supposed to be the default value, you can set this value in the reset() method of the ActionForm bean.

2- You can set it in an Action class that forwards to the JSP

3- You can set it in the JSP itself with a <c:set> tag.
[ August 18, 2006: Message edited by: Merrill Higginson ]
 
Die Fledermaus does not fear such a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic