jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Help me regarding select value in html:select... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Help me regarding select value in html:select..." Watch "Help me regarding select value in html:select..." New topic

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

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
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>

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.

********Deserve Before You Desire********
Merrill Higginson
Ranch Hand

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

Consultant, Sima Solutions
I agree. Here's the link: http://aspose.com/file-tools
subject: Help me regarding select value in html:select...
It's not a secret anymore!