[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: getMessages().format(key, Object[]) not working
From:       "Matt Raible" <mraible () gmail ! com>
Date:       2006-03-30 16:25:15
Message-ID: 7feebe1f0603300825r6cb3ba08r93321e49acf4cc15 () mail ! gmail ! com
[Download RAW message or body]

I figured it was something easy - thanks Andy!

Matt

On 3/29/06, andyhot@di.uoa.gr <andyhot@di.uoa.gr> wrote:
> You forgot to cast to Object[]
> return getMessages().format(key, (Object[])arg);
>
> Also,
> return getMessages().format(key, new Object[] { arg });
> can become
> return getMessages().format(key, arg );
>
>
>
> From  Matt Raible <mraible@gmail.com>:
>
> > I have the following in a base class for my Tapestry pages to extend:
> >
> >     protected String getText(String key, Object arg) {
> >         if (arg == null) {
> >             return getText(key);
> >         }
> >
> >         if (arg instanceof String) {
> >             return getMessages().format(key, new Object[] { arg });
> >         } else if (arg instanceof Object[]) {
> >             return getMessages().format(key, arg);
> >         } else {
> >             log.error("argument '" + arg + "' not String or Object[]");
> >
> >             return "";
> >         }
> >     }
> >
> > Passing in a key, or a single String argument works fine:
> >
> > getText("user.added", user.getFullName());
> >
> > However, if I pass in an Object array, the substituted values get garbled:
> >
> > getText("login.passwordHint.sent", new Object[] {username, user.getEmail()})
> >
> > login.passwordHint.sent=The password hint for <strong>{0}</strong> has
> > been sent to <strong>{1}</strong>.
> >
> > Results in:
> >
> > The password hint for <strong>[Ljava.lang.Object;@1ce1387</strong> has
> > been sent to <strong>{1}</strong>.
> >
> > Any ideas?
> >
> > Thanks,
> >
> > Matt
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> >
>
>
> --
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic