This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Struts and the fly likes Using SELECTED in an html:option tag Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Using SELECTED in an html:option tag" Watch "Using SELECTED in an html:option tag" New topic
Author

Using SELECTED in an html:option tag

Andy Deighton
Ranch Hand

Joined: Apr 01, 2003
Posts: 39
Hi,
Does anyone know I can achieve the following:
<html ption value="Default" SELECTED>Default</html ption>
I know that SELECTED is not supported in Struts, so was wondering what the alternative approach is. I basically have a drop-down of countries and what to pre-select a particular one. Sounds simple? I wish!!
Regards,
Andy
UK
[ August 22, 2003: Message edited by: Andy Deighton ]
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
The "property" attribute of the <html:select> tag indicates a property of a bean or ActionForm which hold the "selected" value for your drop down.
Let's say your ActionForm has a property "book", and you have a JSP page where the user is supposed to select a book from a drop down.

If your ActionForm contains the value "Brave New World" for the property "book", then when your JSP renders, "Brave New World" will be SELECTED in your drop down.
HTH


Jason's Blog
Andy Deighton
Ranch Hand

Joined: Apr 01, 2003
Posts: 39
That worked excellently - many thanks. I just did lazy initialization on the appropriate accessor and bingo, the right default value is selected. Thanks again,
Andy
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Using SELECTED in an html:option tag
 
Similar Threads
how to fill a combobox with values from objects in an ArrayList...
how to set option to default ?
update html:options
Help me regarding select value in html:select...
Setting a preselected value in a combo