jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Show last value in the html:select Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Show last value in the html:select" Watch "Show last value in the html:select" New topic

Show last value in the html:select

Ranch Hand

Joined: Oct 09, 2003
Posts: 517
Hi all,

I have a query.

I have to show last value of the html:select as default vale in the form.How can i show that plz help me..

In the collection ,imagine there are three values, Orange,Grape,Apple
I have to show the last one Apple in the combo box.

Thanks in advance.

God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
If you're using <htmlptions> along with your <html:select>, the option selected will be the option that matches the value in the ActionForm property you specified in the <html:select tag. So, if you specified:

<html:select property="fruit" >
<htmlptions name="myForm" property="fruits" />

At some point prior to the page being displayed (either in your Action class, or in the reset() method of your ActionForm bean) add the following statment:


If it has to be the last option, no matter what it is, then code the following:


This assumes that getFruits() returns a List.
[ April 20, 2006: Message edited by: Merrill Higginson ]

Consultant, Sima Solutions
I agree. Here's the link: http://aspose.com/file-tools
subject: Show last value in the html:select
jQuery in Action, 3rd edition