Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show last value in the html:select

 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic