-
1. Re: pass a variable to a message-key
niox.nikospara.yahoo.com Mar 23, 2010 6:57 PM (in response to nimo22)Hi,
What I do is create an EL function named x:strcat and use it as follows:
<s:selectItems value="#{users}" var="i" label="#{messages[x:strcat('hobby.' , _s]}"/>
I had written a detailed description on how to create such a function here (its very simple actually) and there are plenty of examples in the web!
-
2. Re: pass a variable to a message-key
thokuest Mar 23, 2010 8:44 PM (in response to nimo22)That's even easier:
<s:selectItems value="#{users}" var="i" label="#{messages['hobby.'.concat(_s)]}"/>
By the way: what is _s?
-
3. Re: pass a variable to a message-key
nimo22 Mar 24, 2010 3:54 PM (in response to nimo22)hello thanks.
sorry I have ment that:
<s:selectItems value="#{users}" var="_s" label="#{messages[hobby.#{_s}]}"/>
So you see, I want to pass the variable
"_s"
into my message-bundle.
So Thomas, your solution will not work.
Nikos, I am not sure, if your solution works.
I do not concat a static string
"_s"
with hobby - the string is only available via
#{_s}
.
Any Ideas?
-
4. Re: pass a variable to a message-key
thokuest Mar 24, 2010 5:09 PM (in response to nimo22)So, hobby is your message key?
-
5. Re: pass a variable to a message-key
thokuest Mar 24, 2010 7:43 PM (in response to nimo22)
Any Ideas?If you have the following message key
hobby=Your hobby is #{_s}
you only have to write
<s:selectItems value="#{users}" var="_s" label="#{messages['hobby']}"/>
and #{_s} will resolved to it's current value.
Alternatively, you can introduce a utility component that interpolates the message for you:
@Name("messageUtil") @BypassInterceptors pubic class MessageUtil { public String getMessage(String key, Object... params) { SeamResourceBundle resourceBundle = (SeamResourceBundle) Component .getInstance("org.jboss.seam.core.resourceBundle", true); if (!resourceBundle.containsKey(key)) { return key; } return Interpolator.instance().interpolate(resourceBundle.getString(key), params); } }
Your message key should look like the following:
hobby=Your hobby is {0}
You can use the component like this:
<s:selectItems value="#{users}" var="_s" label="#{messageUtil.getMessage('hobby', _s)}"/>
Hope that helps!
-
6. Re: pass a variable to a message-key
nimo22 Mar 25, 2010 8:51 AM (in response to nimo22)Thank you!!