struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <>
Subject Re: can I use resource keys in html:optionsCollection?
Date Wed, 18 Feb 2004 16:06:13 GMT
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
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"/>

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;


----- Original Message ----- 
From: "Glanville, Jay" <>
To: <>
Sent: Wednesday, February 18, 2004 2:06 PM
Subject: can I use resource keys in html:optionsCollection?

I've looked in the documentation and I can't find my answer, so I'm
assuming that the answer is "no".  However, I'm posing the question to
this list in case I've missed something.

I'm using an <html:optionsCollection> tag to display a list of options
inside my <html:select> tag.  However, I want the labels not to be
directly populated from collection.label, but from my resource bundle
through keys.  In other words, I don't want my collection to be a set of
label - value pairs, but to be a set of label key - value pairs.

Is there a way to have optionsCollection use label keys as opposed to

I've thought of two ways that I can work around this limitation, but I'd
prefer to use the simpler html:optionsCollection method.  My workarounds
1) to use <logic:iterate> to iterate over the collection, and then use
individual <html:option> tags using the key attribute.
2) when creating my collection, resolve my bundle key into a bundle
value for the collection's value attribute.

So, suggestions? Feedback? Help?



Jay Glanville

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message