You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Tim Stephenson <ts...@gmail.com> on 2008/03/10 23:07:32 UTC

[Tobago] How to substitute into the Tobago resource bundle messages?

Hi,

I have loaded a resource bundle using
    <tc:loadBundle basename="messages" var="bundle" />
and can output messages from the bundle like this:
    <tc:out value="#{bundle.title}" />
where the relevant line of the resource bundle props file is
    title = Welcome
which is all fine. But how can i substitute values into the resource
bundle message?

I tried putting this in the props file
    title = Welcome {0}
and this into the jsp:
	<tc:out value="#{bundle.title}">
		<f:param value="#{bean.name}"></f:param>
	</tc:out>
following the examples of JSF core, but apparently the tc control does
not understand the param as I just see Welcome {0} output without any
substitution.

Is there some other way to achieve this for Tobago resource bundles?

thanks in advance

-- 
Tim Stephenson
e: tim@thestephensons.me.uk

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Stojan Peshov <go...@gmail.com>.
Or, you could always rely on the getter like this:

public String getLocalizedTitle(){
            Locale locale = FacesContext.getCurrentInstance
().getViewRoot().getLocale();
            MessageFormat detail = new MessageFormat(title, locale);
            Object[] args = {getLoggedUserName()};
            return detail.format(args);
}

I use this in my applications

Regards,
Stojan


On Tue, Mar 11, 2008 at 11:59 PM, Volker Weber <v....@inexso.de> wrote:

> Hi Tim,
> You could create very complex value bindings :-)
> We have something like this, and more complex ones in one app:
> value="#{bundle.editUser}#{empty controller.user ? '' : ' ( '}#{empty
> controller.user ? '' : controller.user.name}#{empty controller.user ?
> '' : ' ) '}"
>
> But i like the idea of formating such values/labels with MessageFormat
> and params.
>
> Regards,
>
>  Volker
>

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Tim Stephenson <ts...@gmail.com>.
Hi,

I created TOBAGO-636 and included an example of how this would be done
using the JSF tags.

regards, tim

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Volker Weber <v....@inexso.de>.
Hi Tim,

2008/3/11, Tim Stephenson <ts...@gmail.com>:
> Thanks Volker
>
> Does this mean it never will or it would be a reasonable enhancement

feel free to add a enhancement request at jira.


> request? If the first does that mean i should always use the jsf core / html
> tags?

Did jsf core / html support this? I didn't know that.

>
> Obviously a more complex example would have the {0} in the middle of the
> resource string
>

You could create very complex value bindings :-)
We have something like this, and more complex ones in one app:
value="#{bundle.editUser}#{empty controller.user ? '' : ' ( '}#{empty
controller.user ? '' : controller.user.name}#{empty controller.user ?
'' : ' ) '}"

But i like the idea of formating such values/labels with MessageFormat
and params.

Regards,

  Volker


> tim
>
> On 11/03/2008, Volker Weber <v....@inexso.de> wrote:
> > Hi Tim,
> >
> > tobago resourceBundle did not support argument formating.
> >
> > in your case you can concatenate the two values into a single
> valueBinding:
> >
> >   <tc:out value="#{bundle.title} #{bean.name}" />
> >
> >
> > Regards,
> >     Volker
> >
> >
> > 2008/3/10, Tim Stephenson <ts...@gmail.com>:
> >
> > > Hi,
> > >
> > >  I have loaded a resource bundle using
> > >    <tc:loadBundle basename="messages" var="bundle" />
> > >  and can output messages from the bundle like this:
> > >    <tc:out value="#{bundle.title}" />
> > >  where the relevant line of the resource bundle props file is
> > >    title = Welcome
> > >  which is all fine. But how can i substitute values into the resource
> > >  bundle message?
> > >
> > >  I tried putting this in the props file
> > >    title = Welcome {0}
> > >  and this into the jsp:
> > >        <tc:out value="#{bundle.title}">
> > >                <f:param value="#{bean.name}"></f:param>
> > >        </tc:out>
> > >  following the examples of JSF core, but apparently the tc control does
> > >  not understand the param as I just see Welcome {0} output without any
> > >  substitution.
> > >
> > >  Is there some other way to achieve this for Tobago resource bundles?
> > >
> > >  thanks in advance
> > >
> > >
> > >  --
> > >  Tim Stephenson
> > >  e: tim@thestephensons.me.uk
> > >
> >
> >
> >
> > --
> > inexso - information exchange solutions GmbH
> > Bismarckstraße 13      | 26122 Oldenburg
> > Tel.: +49 441 4082 356 |
> > FAX:  +49 441 4082 355 | www.inexso.de
> >
>
>
>
> --
> Tim Stephenson
>  e: tim@thestephensons.me.uk


-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Tim Stephenson <ts...@gmail.com>.
Thanks Volker

Does this mean it never will or it would be a reasonable enhancement
request? If the first does that mean i should always use the jsf core / html
tags?

Obviously a more complex example would have the {0} in the middle of the
resource string

tim

On 11/03/2008, Volker Weber <v....@inexso.de> wrote:
>
> Hi Tim,
>
> tobago resourceBundle did not support argument formating.
>
> in your case you can concatenate the two values into a single
> valueBinding:
>
>   <tc:out value="#{bundle.title} #{bean.name}" />
>
>
> Regards,
>     Volker
>
>
> 2008/3/10, Tim Stephenson <ts...@gmail.com>:
>
> > Hi,
> >
> >  I have loaded a resource bundle using
> >    <tc:loadBundle basename="messages" var="bundle" />
> >  and can output messages from the bundle like this:
> >    <tc:out value="#{bundle.title}" />
> >  where the relevant line of the resource bundle props file is
> >    title = Welcome
> >  which is all fine. But how can i substitute values into the resource
> >  bundle message?
> >
> >  I tried putting this in the props file
> >    title = Welcome {0}
> >  and this into the jsp:
> >        <tc:out value="#{bundle.title}">
> >                <f:param value="#{bean.name}"></f:param>
> >        </tc:out>
> >  following the examples of JSF core, but apparently the tc control does
> >  not understand the param as I just see Welcome {0} output without any
> >  substitution.
> >
> >  Is there some other way to achieve this for Tobago resource bundles?
> >
> >  thanks in advance
> >
> >
> >  --
> >  Tim Stephenson
> >  e: tim@thestephensons.me.uk
> >
>
>
>
> --
> inexso - information exchange solutions GmbH
> Bismarckstraße 13      | 26122 Oldenburg
> Tel.: +49 441 4082 356 |
> FAX:  +49 441 4082 355 | www.inexso.de
>



-- 
Tim Stephenson
e: tim@thestephensons.me.uk

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Volker Weber <v....@inexso.de>.
Hi Tim,

tobago resourceBundle did not support argument formating.

in your case you can concatenate the two values into a single valueBinding:

  <tc:out value="#{bundle.title} #{bean.name}" />


Regards,
    Volker


2008/3/10, Tim Stephenson <ts...@gmail.com>:
> Hi,
>
>  I have loaded a resource bundle using
>    <tc:loadBundle basename="messages" var="bundle" />
>  and can output messages from the bundle like this:
>    <tc:out value="#{bundle.title}" />
>  where the relevant line of the resource bundle props file is
>    title = Welcome
>  which is all fine. But how can i substitute values into the resource
>  bundle message?
>
>  I tried putting this in the props file
>    title = Welcome {0}
>  and this into the jsp:
>        <tc:out value="#{bundle.title}">
>                <f:param value="#{bean.name}"></f:param>
>        </tc:out>
>  following the examples of JSF core, but apparently the tc control does
>  not understand the param as I just see Welcome {0} output without any
>  substitution.
>
>  Is there some other way to achieve this for Tobago resource bundles?
>
>  thanks in advance
>
>
>  --
>  Tim Stephenson
>  e: tim@thestephensons.me.uk
>


-- 
inexso - information exchange solutions GmbH
Bismarckstraße 13      | 26122 Oldenburg
Tel.: +49 441 4082 356 |
FAX:  +49 441 4082 355 | www.inexso.de

Re: [Tobago] How to substitute into the Tobago resource bundle messages?

Posted by Tim Stephenson <ts...@gmail.com>.
Hi,

I have loaded a resource bundle using
   <tc:loadBundle basename="messages" var="bundle" />
and can output messages from the bundle like this:
   <tc:out value="#{bundle.title}" />
where the relevant line of the resource bundle props file is
   title = Welcome
which is all fine. But how can i substitute values into the resource
bundle message?

I tried putting this in the props file
   title = Welcome {0}
and this into the jsp:
       <tc:out value="#{bundle.title}">
               <f:param value="#{bean.name}"></f:param>
       </tc:out>
following the examples of JSF core, but apparently the tc control does
not understand the param as I just see Welcome {0} output without any
substitution.

Is there some other way to achieve this for Tobago resource bundles?

thanks in advance

--
Tim Stephenson
e: tim@thestephensons.me.uk