Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display the last item of a select box as default

 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
Iam using logic iterate tag,using iteration i have to display some items in the select box,
how to display the last item as default value?
(Please let me know whether I have given enough details...)
Thank you in advance,
ramna
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use Struts tags to display the select box (<html:select> and <htmlptions> or <htmlptionsCollection>) The value that will show as selected is tied to the property of the ActionForm bean specified in the tag. For example, if you specify <html:select property="foo" > and in your Action form, calling getFoo() returns "xyz". The option that will show as selected is the one with value="xyz".

See this link in the JavaRanch Struts FAQ for more details.
[ February 12, 2007: Message edited by: Merrill Higginson ]
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill Higginson ,
Iam not using <html:select>,its just select box.
ramna
 
Ramna Reddy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Merrill Higginson ,
Actually i have two conditions to check for
The List object may contain(A to D alphabets)
1)if the list contains B,it should display B as default
else
the last item of the list.

I could able to display B,if it is in the list ,if not,I couldn't able to display the last item.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest you change your JSP so that it does use <html:select>. While there are ways to do it otherwise, it's much easier with the Struts tags.

Since this is a Struts forum, I'm proposing a Struts solution. Since it appears you want a solution using regular HTML and JSP tags, I'm transferring this thread to the JSP forum.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got blind or what. Is it really something related to Struts? Sorry, I am asking because I am not seeing anything like that in the original post.

[Edited]
Got it. No worries.
[ February 13, 2007: Message edited by: Adeel Ansari ]
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Merrill Higginson:
I'd suggest you change your JSP so that it does use <html:select>. While there are ways to do it otherwise, it's much easier with the Struts tags.


Thats not true. Why one would start using struts just for this thing?

You can use,
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adeel,

Just a little history:

This was originally posted in the Struts forum. Generally it can be assumed that if someone posts in the Struts forum, their application already has been built around Struts. If one already has a Struts application, it is in fact true that it's easier to use the Struts tags.

As it became clear that Ramna may not be looking for a Struts solution, but simply posted to the wrong forum, I then moved the thread to the JSP forum hoping that one of you friendly and helpful developers who frequent the JSP forum could help Ramna out.

I hope this clarifies it.

Merrill
[ February 13, 2007: Message edited by: Merrill Higginson ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64858
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though I'm not a fan of Struts, if your app is already using Struts it's probably best to do things in "the Struts way". Is there a reason you are not wanting to use the Struts tags?

In any case, to take this any further, please show the JSP code that you are using to populate the select element and its options so we can be of help.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its so confusing. Please let me say it bold to make the thread clear.

   Its Not At All About Struts

Now please proceed.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic