• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help me regarding select value in html:select...

 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In my JSP page I am using following code for displaying selst tag:-
<html:select name="userForm1" value="active" >
<html ption value="pending" >pending</html ption>
<html ption value="active">active</html ption>
<html ption value="blacklisted">blacklisted</html ption>
<html ption value="cancel">cancel</html ption>
<html ption value="denied">denied</html ption>
</html:select>

Now according to this tag when JSP page gets loaded, by default the second option of html:select "active" should be selected(as I am specifying value attribute for html:select as "active").
But when I am loading my jsp page, At all the times I am seeing the first option "pending" as selected. Why it is happening? Also if I want to get second option displayed as selected, what should I do for that?
Please help me.
Thank you.
Prashant
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <html:select> tag gets its value from the property you specify. The tag you showed us:

<html:select name="userForm1" value="active" >

doesn't even specify a property attribute. Since a property attribute is required, I'm surprised the page even compiled at all. Or perhaps you didn't paste the full tag onto your post.

The way to pre-select one of the options is not to specify a value attribute, but to set the form bean property to the value of the option you want. The preferred place to do this would be in the Action class that forwards to this JSP. You could also do it in the JSP, like this:

<c:set target="userForm1" property="myProperty" value="active" />
<html:select name="userForm1" property="myProperty" >
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic