0

After fruitlessly spending a few days on this, I find myself realizing I should have asked on SO sooner.

I have some property files, ending in .properties, however i don't care what they end up being named.

I have a database. The database will store the name of the properties file to use when displaying strings in JSP's for a given user.

I have some JSP pages being served with the help of spring-mvc. The JSP pages are the most inflexible... they are already coded up to display strings from the properties file, using the following syntax: <fmt:message key="someVariable.fromPropertiesfile"/>

This is what needs to happen:

A user logs in and depending on which user they are, the name of the properties file to use for that user is retrieved from the database. Then "somehow", the application needs to associate those values with that user's session, for the JSPs to be able to access.

This problem was already solved for the case of a single properties file for all users, the JSPs have already been written. Therefore a solution where all JSPs do not need to be modified is preferred if this is possible.

Every example I have found for doing anything even remotely like this does not take into account that the properties file is selected in the application's java code.

Please show how, assuming the application's java code has chosen the name of a properties file, I can get that .properties file loaded for use in that session by all my JSP's. If the syntax I quoted above will not work, please provide a real example of what does.

I have tried to solve this using both PropertyPlaceholderConfigurer and the oft-suggested ReloadableResourceBundleMessageSource, and each time failed miserably.

This is NOT a question about how to localize, the language does not change and neither do the Locale's in question.


Edit based on comments:

The jsp's all have the following at the top. Editing this however is much more palatable than editing all the places in which a property value is displayed using the indicated code.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib tagdir="/WEB-INF/tags/xf" prefix="xf" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
user1445967
  • 1,520
  • 4
  • 14
  • 30
  • Maybe this helps: http://stackoverflow.com/questions/1771166/access-properties-file-programatically-with-spring – developerwjk Feb 07 '14 at 00:57
  • Thank you for the suggestion! I can already load the files as Properties objects and have java code choose which object I want to make accessible to JSPs. If you have a clear example of how to take ONE of those Properties objects and make it available in a JSP, that would completely solve my issue. – user1445967 Feb 07 '14 at 01:00
  • So you're looking up a `.properties` file from the classpath and want to make the `Properties` accessible from a JSP? How about `request.setAttribute("props", org.springframework.core.io.support.PropertiesLoaderUtils.loadProperties(new org.springframework.core.io.ClassPathResource("path/to/x.properties")))`? – superEb Feb 07 '14 at 01:16
  • @superEb that looks promising, however the properties must be placed in session scope, I believe I can do this with getSession(). Is there a way to massage this to be displayed by the existing jsp's `` ? – user1445967 Feb 07 '14 at 01:34
  • Does the JSP also contain a `fmt:bundle` tag? – superEb Feb 07 '14 at 01:38
  • @superEb edited question, it has `fmt` but not `fmt:bundle` – user1445967 Feb 07 '14 at 01:49

0 Answers0