You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Miguel Figueiredo <ol...@gmail.com> on 2013/07/01 23:57:10 UTC

Tapestry grid with enum override localization

Hi,

I need to add a column override that contains an enum, but I am having
trouble localizing it.

For example:

<t:grid source="datasource" row="rowElement">
  <p:columnCell>
    ${rowElement.column}
  </p:columnCell>
</t:grid>

My rowElement.column corresponds to an enum like:

enum Column {
  A, B
}

Tapestry will display A or B in the table.
How can I render an localized string based on an enum using the column
override?

Best regards,
Miguel

-- 
Miguel Figueiredo
Software Developer
http://jaragua.hopto.org <http://jaragua.dyndns.org>

"I'm a pretty lazy person and am prepared to work quite hard in order to
avoid work."
-- Martin Fowler

Re: Tapestry grid with enum override localization

Posted by Miguel Figueiredo <ol...@gmail.com>.
Hi Chris,

Your suggestion works perfectly.

In the getColumnLabel() implementation, I also tried the following:

    public String getColumnLabel() {
        return TapestryInternalUtils.getLabelForEnum(messages,
rowElement.getColumn());
    }

Like this I can use the standard properties for enums:

Column.A=LocalizedA
Column.B=LocalizedB

Thanks for the help,
Miguel


On Tue, Jul 2, 2013 at 8:08 AM, Christian Köberl <
tapestry.christian.koeberl@gmail.com> wrote:

> 2013/7/1 Miguel Figueiredo <ol...@gmail.com>:
> > Hi,
> Hi
>
> > I need to add a column override that contains an enum, but I am having
> > trouble localizing it.
> >
> > For example:
> >
> > <t:grid source="datasource" row="rowElement">
> >   <p:columnCell>
> >     ${rowElement.column}
> >   </p:columnCell>
> > </t:grid>
> >
> > My rowElement.column corresponds to an enum like:
> >
> > enum Column {
> >   A, B
> > }
>
> Just create a getter in your page/component
>
> public String getColumnLabel()
> {
>   return messages.get(rowElement.getColumn().name() + "-label");
> }
>
> with the corresponding labels in your properties:
> A-label=Alabel
> B-label=The "B"
>
> then you can use that in your template:
> <t:grid source="datasource" row="rowElement">
>   <p:columnCell>
>     ${columnLabel}
>   </p:columnCell>
> </t:grid>
>
> > Best regards,
> > Miguel
>
> Cheers,
> Chris
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Miguel Figueiredo
Software Developer
http://jaragua.hopto.org <http://jaragua.dyndns.org>

"I'm a pretty lazy person and am prepared to work quite hard in order to
avoid work."
-- Martin Fowler

Re: Tapestry grid with enum override localization

Posted by Christian Köberl <ta...@gmail.com>.
2013/7/1 Miguel Figueiredo <ol...@gmail.com>:
> Hi,
Hi

> I need to add a column override that contains an enum, but I am having
> trouble localizing it.
>
> For example:
>
> <t:grid source="datasource" row="rowElement">
>   <p:columnCell>
>     ${rowElement.column}
>   </p:columnCell>
> </t:grid>
>
> My rowElement.column corresponds to an enum like:
>
> enum Column {
>   A, B
> }

Just create a getter in your page/component

public String getColumnLabel()
{
  return messages.get(rowElement.getColumn().name() + "-label");
}

with the corresponding labels in your properties:
A-label=Alabel
B-label=The "B"

then you can use that in your template:
<t:grid source="datasource" row="rowElement">
  <p:columnCell>
    ${columnLabel}
  </p:columnCell>
</t:grid>

> Best regards,
> Miguel

Cheers,
Chris

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