I have a Spring MVC project that uses Apache Tiles. I implemented it so that the headers could be read from the message source as follows:
<tiles-definitions> <definition name="some-definition" extends="public.base"> <put-attribute name="title" value="some-definition.title" cascade="true" /> </definition> </tiles-definitions>
And in my template file (defined by public.base ), I do the following:
<title><spring:message text="" code="${title}" /></title>
Now this works fine for static translated titles, but I also want to support dynamic headers, for example. to display the company name. I could do it like this:
<tiles-definitions> <definition name="some-definition" extends="public.base"> <put-attribute name="title" expression="${company.name}" /> </definition> </tiles-definitions>
And then just print the title in my template as follows: <c:out value="${title}" /> . However, the problem is that my code breaks because the value of the title attribute is no longer the message key. I want to be able to support the following scenarios:
- Static headers, for example. "About us"
- Purely dynamic headers, for example. "$ {Company.name}"
- Dynamic headers with translated content, for example. "Welcome to $ {company.name}"
Ideally, I could use an expression language in my message source, but I could not get this to work. I experimented a lot with various solutions, but I can not find the right one. If I could use the expression language in my message source, that would be easy. For example, is it possible to somehow do the following?
some-definition.title = Hello there, ${company.name}
And in my template:
<spring:message text="" code="some-definition.title" var="test" /> <c:out value="${test}" />
The above does not work as it displays ${company.name} , not the actual contents of the variable. Is there a way to do something like this work? Or are there other ways I can support the scripts listed above?
I was thinking of creating a custom JSTL tag where I would parse a string expression in plain Java code (the string that was translated), but I realized that I probably would have to explicitly specify the root object to "replace variables" "work like described here , then it doesn't look like such a dynamic solution.
Is there a way I can complete this task? Any help is much appreciated!