> No you can't use <html:optionsCollection> tag to display labels.
>
> I also can't think why this would be necessary - if you
> define your options
> in your resource bundle, you know how many there are going to
> be and so you
> can just use straight <html:option> tags. For example:
>
> In your resource bundle:
> order.status.placed=Order Placed
> order.status.delivered=Goods Deleivered
> order.status.cancelled=Cancelled
> In yout jsp:
> <html:option value="1" key="order.status.placed"/>
> <html:option value="2" key="order.status.delivered"/>
> <html:option value="3" key="order.status.cancelled"/>
>
Actually, just because you know what the list possible options are,
doesn't mean you know at JSP authoring time which of those options
you're going to present to the user. For example, you might have a list
of options that you want to present if the current user is an
administrator, and a subset of those options if the current user is a
non-administrator. My situation is just like this, I have an action
that populates the list based on the current user's access level.
Therefore, using <html:option key="" /> isn't appropriate.
> If you do have a good reason for doing this however, an
> alternative to the
> two solutions you are considering would be to have your own
> custom tag based
> on the <html:optionsCollection> tag - which I think could be done very
> easily, by overriding the addOption() method:
>
> public class KeyOptionsCollectionTag extends OptionsCollectionTag {
>
> protected String bundle = Globals.MESSAGES_KEY;
> protected String locale = Globals.LOCALE_KEY;
>
> protected void addOption(StringBuffer sb, String key,
> String value,
> boolean matched) {
> String label =
> TagUtils.getInstance().message(pageContext, bundle,
> locale, key);
> super.addOption(sb, label, value, matched);
> }
>
> public String getBundle() {
> return (this.bundle);
> }
> public void setBundle(String bundle) {
> this.bundle = bundle;
> }
> public String getLocale() {
> return (this.locale);
> }
> public void setLocale(String locale) {
> this.locale = locale;
> }
> }
Good suggestion. That one honestly hadn't occurred to me! Now that I
think about it a little more, I suppose a fourth possible solution is to
modify the optionsCollection implementation and add a labelKey
attribute. That way, other users could use my solution.
JDG
--
Jay Glanville
Web Developer
[EMAIL PROTECTED]
(613) 725-2030 x393
http://www.naturalconvergence.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]