aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Show last value in the html:select" Watch "Show last value in the html:select" New topic
Author

Show last value in the html:select

MInu
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" />
</html:select>

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:

myForm.setFruit("Apple");

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

myForm.setFruit(myForm.getFruits().get(myForm.getFruits().size()-1);

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

Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Show last value in the html:select