aspose file tools*
The moose likes JSP and the fly likes How to display the last item of a select box as default 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 » Java » JSP
Bookmark "How to display the last item of a select box as default" Watch "How to display the last item of a select box as default" New topic
Author

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

Ramna Reddy
Ranch Hand

Joined: Aug 06, 2006
Posts: 96
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

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Ramna Reddy
Ranch Hand

Joined: Aug 06, 2006
Posts: 96
Hi Merrill Higginson ,
Iam not using <html:select>,its just select box.
ramna
Ramna Reddy
Ranch Hand

Joined: Aug 06, 2006
Posts: 96
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Jan 10, 2002
Posts: 61432
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Its so confusing. Please let me say it bold to make the thread clear.

   Its Not At All About Struts

Now please proceed.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to display the last item of a select box as default