Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts - DropDown Combination

 
auvrm papu
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a dropdown in Struts-Jsp page

Iam displaying the State description the drop-down
The values would be for ex:
Alabama
Minnesota
etc..
using....

<html:select name="<%=formName%>" property="selectedState" >
<app ptionsCollection
name="<%=formName%>"
property="states"
label="description"
value="id"

/>

</html:select>

I would like to display them as,
AL- Alabama
MN- Minnesota
etc

basically, I want to have..
label="code-description"..

something like that..any idea?
 
Dave Hayward
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it were me, I would create a new getter method in the form that would return what you want. Something like:

Then in your html:select you would use "combinedLabel" instead of "description" for the label. Make sense?
You may not have this option, but it seems the easiest to me.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave's suggestion is good. Another option would be to iterate through the list of records returned from the database and populate your form with a list of LabelValueBean objects that have the desired label value.

BTW, I am a little curious about your usage of name="<%=formName%>". By default the html tags use the form name of the enclosing html:form tag if a name property is not given. I cannot remember a case where I used a scriptlet to populate the property.

- Brent
[ March 01, 2007: Message edited by: Brent Sterling ]
 
auvrm papu
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave, Thanks your idea worked..

Originally posted by Dave Hayward:
If it were me, I would create a new getter method in the form that would return what you want. Something like:

Then in your html:select you would use "combinedLabel" instead of "description" for the label. Make sense?
You may not have this option, but it seems the easiest to me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic