-
1. Re: Dynamic key name for labels
damianharvey.damianharvey.gmail.com Mar 27, 2008 6:12 PM (in response to chawax)You can't specify an expression inside an expression like that. You might want to lookup concentenate JSF functions to combine 'label.' with transition to pass into messages. There was a thread about this last week I think (search for concatenate).
Or you could always override the org.jboss.seam.international.Messages class (where #{messages} comes from) and put your
label.
in there. Usage would then be something like<s:button value="#{mymessages[transition]}" />
Cheers,
Damian.
-
2. Re: Dynamic key name for labels
chawax Mar 28, 2008 10:33 AM (in response to chawax)Thanks Damian for your response.
I like your suggestion of overriding the Messages class. Unfortunately the label. prefix was just an example and most of the time I have no idea what the prefix will be.Anyway I created a Seam component to solve my problem.
@Name("messageUtils") @Scope(ScopeType.STATELESS) public class MessageUtils { public String getDynamicMessage(String prefix, String key) { StringBuffer sb = new StringBuffer(); sb.append(prefix); sb.append(key); return SeamResourceBundle.getBundle().getString(sb.toString()); } }
Then I can use it this way :
<ui:repeat value="#{task.transitions}" var="transition"> <s:button value="#{messageUtils.getDynamicMessage('label.demandeAbsence.', transition)}" action="#{validationDemandesAbsenceAction.choisirTransitionTache(task.idTache, transition)}" /> </ui:repeat>
Best regards,
Olivier
-
3. Re: Dynamic key name for labels
damianharvey.damianharvey.gmail.com Mar 28, 2008 11:20 AM (in response to chawax)No worries. You should probably throw an @BypassInterceptors on that class as well. For usage like this it improves performance (there's a long long thread on it somewhere in this forum).
And if you're well keen, then apparently EL functions are more performant that using a Bean in this manner (although I use them the same way as this without any trouble).
Cheers,
Damian.
-
4. Re: Dynamic key name for labels
chawax Mar 28, 2008 12:01 PM (in response to chawax)Thanks for the tip about @BypassInterceptors.
About EL functions, will it be possible to use Seam built-in components if the class containing the EL functions is not itself a Seam component ? And then I can't see the difference between EL functions and Seam components. I had posted a JIRA about the ability to extend the list of EL functions supporters by Seam EL resolver a few months ago, don't know if it has been token in account.
By the way, I have another strange problem with dynamic EL expressions. The transition variable is known when using my messageUtils component. But when I use my other component on action attribute of my s:button, the transition variable is an empty string !
Can't understand why since there is no problem with task.idTache parameter and both methods consider transition parameter as a String ... Do you have any idea where it could come from ?
-
5. Re: Dynamic key name for labels
tom_goring Mar 28, 2008 1:08 PM (in response to chawax)EL functions are static methods on simple class (non-seam component).
But you can pass on the request to a seam component however....
e.g.
public static String descriptionForOptionList(String listKey, String value) { UserPreferencesBean bean = (UserPreferencesBean)Component.getInstance(UserPreferencesBean.class, ScopeType.SESSION); return bean.descriptionForOptionList(listKey, value); }