java - adding second level data in properties file -


what have properties file below.

welcome.properties

admin = admin welcomeadmin = welcome admin editadmin = edit admin 

as have repeated admin word, want use below.

admin = admin welcomeadmin = welcome #{admin} editadmin = edit #{admin} 

so if change @ 1 place i.e. @ admin = admin, places reflect.

any idea/ suggestion how done appreciated.

as per today, classic resourcebundle class doesn't support named parameters , substitution, rather supports simple placeholders of {0} type in key-value pairs of bundles, substituted using messageformat#format.

in light if replace welcome #{admin} welcome {0} you'd able achieve functionality seek using 1 of following:

  1. jsf's <h:outputformat>:

    <h:outputformat value="#{msg.welcomeadmin}">     <f:param value="#{msg.admin}" /> </h:outputformat> 
  2. jstl's <fmt:message>:

    <fmt:message key="msg.welcomeadmin">     <fmt:param value="#{msg.admin}"> </fmt:message> 

you create own el function, or tag handler, or ui component, or make use of messageformat class methods in beans, etc. of course, extend resourcebundle class support named parameters , return message named parameters parsed.

suggested reading:

  1. do resource bundles in java support runtime string substitution?;
  2. how use parameterized messageformat non-value attributes of jsf components;
  3. pass parameters messages resource bundle components other h:outputformat.

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -