开发者

How to dynamically pass arguments to messages in the resource bundle

I would like to retrieve the message information from the i18n bundle (messages.properties in seam), but I am not sure 开发者_C百科how to pass the declare / pass the jobCount variable dynamically in my xhtml

The existing code looks like this.

<s:decorate template="/layout/panel-name.xhtml">
    <ui:define name="label">User has been assigned #{jobCount} jobs</ui:define>
</s:decorate>


I think this should work:

<h:outputFormat value="#{msg.yourMessage}">
  <f:param value="#{myBean.jobCount}" />
</h:outputFormat>


I found this fragment of code:

#{interpolator.interpolate(messages['myMessage'],jobCount)}

I think this is what you're searching for. Messages and placeHolders

Otherwise you can use string concatenation (ugly) if it's a static message:

<s:decorate template="/layout/panel-name.xhtml">
    <ui:define name="label">#{messages['myMessage']} #{jobCount}</ui:define>
</s:decorate>

Or if it's a dynamic message and you're using h:message

Use this syntax in the message properties:

myMessage= User has been assigned {1} jobs

And then when you create the message in the bean

@Name("myBean") 
public class Bean {
    @In(create = true) FacesMessages facesMessages;
    @In Map messages;

    public String action() {
         // Action here
         facesMessages.add(messages.get("myMessage"), jobCount);
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜