0

How do I access an element from an array in a properties file?

testKey = word1,word2,word3

Something like this is not working (assume properties file is mapped to "msg"

#{msg.testKey[0]} <- to access first element
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
djmj
  • 5,579
  • 5
  • 54
  • 92

1 Answers1

2

It's a String, not a String[]. You've got to split it on the comma first by fn:split() to get a String[] out of it so that you can access the items by an index.

#{fn:split(msg.testKey, ',')[0]}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I hoped for something like the Java provided function: "String[] java.util.ResourceBundle.getStringArray(String key)" – djmj Feb 25 '12 at 16:01
  • That's unfortunately not possible. It only applies to in-memory properties. – BalusC Feb 25 '12 at 21:15