Reputation: 46137
I have a localized spring mvc based web application, that has an externalized messages resource bundle/file.
A couple of sample messages in the bundle are:
...
msg1=Click here to go to your account
msg2=Click here to go to your inbox
...
As you can see, I have messages that are of the form : 'Click here...". Now, I wish to make the 'click here' part of the message/text as a link, whose destination would be different for each user (for e.g., for 'msg1', user1 would have a link to user1's account, while for user2 the target would be the link to user2's account, and so on).
Could you please let me know how can this be achieved?
Upvotes: 3
Views: 4245
Reputation: 691715
The link should be the same for all the users. Since the users are authenticated, the server should know which user is executing a given request, and should thus use that information, rather than a request parameter, to get the inbox or account of the current user.
That said, if you really need to pass a request parameter which is different for every user, just parameterize your message:
msg1=<a href="{0}">Click here</a> to go to your account
And use your message tag topass the argument. With the JSTL, this would be something like this:
<c:url var="accountUrl" value="/account.action">
<c:param name="userId" value="${currentUserId}"/>
</c:url>
<fmt:message key="msg1">
<fmt:param value="${accountUrl}"/>
</fmt:message>
Upvotes: 3