Internationalization with Enums Labels

0

Hello, I'm trying to internationalize with labels coming from an enum:

public enum WeekDay {
  MONDAY("msg.week_monday", "mon"), 
  TUESDAY("msg.week_tuesday", "tue"), 
  WEDNESDAY("msg.week_wednesday", "wed"),
  THURSDAY("msg.week_thursday", "thu"), 
  FRIDAY("msg.week_friday", "fri"), 
  SATURDAY("msg.week_saturday", "sat"),
  SUNDAY("msg.week_sunday", "sun");

    private String label;
    private String value;

    private WeekDay(String label, String value) {
        this.label = label;
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public String getValue() {
        return this.value;

    }
}

And I call the page like this:

  <f:selectItems value="#{myMB.weekDays}"
                                    var="dayWeek" itemValue="#{dayWeek}"
                                    itemLabel="#{dayWeek.label}" />

But the result is the labels literals and not their corresponding in my msg.properties file:

week_monday=Segunda-feira
week_tuesday=Ter\u00E7a-feira
week_wednesday=Quarta-feira
week_thursday=Quinta-feira
week_friday=Sexta-feira
week_saturday=S\u00E1bado
week_sunday=Domingo

When I call this way itemLabel="#{msg.week_monday}" works, does anyone know how to do it? I'm trying the same problem trying to translate fields from the bank.

    
asked by anonymous 30.03.2016 / 19:25

1 answer

1

Do so within getLabel

FacesContext context = FacesContext.getCurrentInstance();              
FacesContext.getCurrentInstance().getApplication().evaluateExpressionGet(context,  label, String.class);

This code will cause the msg ed bean value to be processed within Enum.

    
31.03.2016 / 15:45