Dear Wiki user, You have subscribed to a wiki page or wiki category on "Struts Wiki" for change notification.
The following page has been changed by MichaelJouravlev: http://wiki.apache.org/struts/StrutsWidgets The comment on the change is: how-to: expression label ------------------------------------------------------------------------------ <html:select name="addressForm" property="currentStateCode" size="1"> <html:optionsCollection name="stateList" value="stateCode" label="stateName"/> </html:select> + }}} + + The {{{stateList}}} is a list of beans with {{{stateCode}}} and {{{stateName}}} properties: + + {{{ + public class State { + private String stateCode; + public String getStateCode() {return stateCode;} + + private String stateName; + public String getStateName() {return stateName;} + + ... + } }}} HTML SELECT can be rendered either as dropdown box or as a listbox. To create a listbox specify ''size'' larger than 1. @@ -24, +38 @@ When the widget is being displayed, it positions to an element that has the same ''value'', as the ''property'' specified in <html:select> tag. inline:selectwidget.gif + + If you want the dropdown box to contain an arbitraty expression you can define a read-only property for that. For example, {{{stateCodeAndName}}} property returns both state code and state name in one string: + + {{{ + public class State { + private String stateCode; + public String getStateCode() {return stateCode;} + + private String stateName; + public String getStateName() {return stateName;} + + public String getStateCodeAndName() { + return stateCode + "(" + stateName + ")"; + } + + ... + } + }}} + + Then use new property as label in <html:optionsCollection> tag: + + {{{ + <html:select name="addressForm" property="currentStateCode" size="1"> + <html:optionsCollection name="stateList" value="stateCode" label="stateCodeAndName"/> + </html:select> + }}} + Using Map is slightly different from using List. When a Map is iterated, it exposes each entry as a Map.Entry record with attributes ''key'' and ''value''. Selectable item is stored in ''value'' attribute of Map.Entry: --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]