This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:select default select label and value

 
ameya n
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following code i got from Struts Survival Guide .........but it does not work.
is it possible it ll work ?

<html:select property="address.state">
<html ption property=�NA�
labelProperty=�--Select One--� />
</html:select>
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes the html:select works... otherwise I wouldn't think they have it in their release. what errors are you getting?
From your code you should have an Address object with name of 'address' in the request that has a string property called state.
 
ameya n
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:select property="address.state">
<html ption property=�NA�
labelProperty=�--Select One--� />
</html:select>

it says property "NA" invalid ........please anyone try the same and let me know

i want to make the default select option here "--Select One--"
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could do this:
<html ption value="NA">--Select One--</html ption>
or this:
<option value="NA" selected="selected">--Select One--</option>

if you put 'property' as an attribute it will look for a property with that name in your form or in the request. The way you have it you're saying you have a bean with an attribute filed called NA (mybean.getNA())... If this is on a form the easiest way to have it auto select is set the default value of your select to "NA" (on your form/bean have address.state = "NA" by default).
 
Nick Williamson
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have questions about the tag lib you should check out

http://struts.apache.org/1.x/struts-taglib/tagreference.html

*note this is for 1.x
 
ameya n
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Nick Williamson
thanks a lot dude ............your help was great ..........i just copy pasted the code earlier from a book....thinking it would be perfect....thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic