0

i have for instance an

enum State { OK, WARN, ERROR } 

and a message.properties with following keys:

my.state.OK=Ok
my.state.WARN=Warning
my.state.ERROR=Error

and given a bean with a property of type State, for instance, bean.state, i would like to display the text for the property's state.

something like:

#{text['my.state.' + bean.state]}

this does not seem to be possible just because the + operator does not work on strings.

any work around?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
mmoossen
  • 1,237
  • 3
  • 21
  • 32

1 Answers1

1

Add an extra property to the enum representing the label key.

public enum State {

    OK, WARN, ERROR;

    private String labelKey;

    private State() {
        this.labelKey = "my.state." + name();
    }

    public String getLabelKey() {
        return labelKey;
    }

}

So that you can reference it as follows:

#{text[bean.state.labelKey]}

This way you don't need to repeat <ui:param name="msgKey" value="my.state.#{bean.state}" /> over all place.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555