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
If you use Struts tags to display the select box (<html:select> and <html:options> or <html:optionsCollection>) 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 ]
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.
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.
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?
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.
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.