Reputation: 28556
I need to use some link as argument to <spring:message />
and use <c:set/>
for that. To have link relative to contextPath i use <c:url>
. Why using <c:url/>
in <c:set/>
inside like below doesn't work ?
<c:set value='<c:url value="/x"/>' var='doc1'/>
<spring:message code="doc.link" arguments="${doc1}"/> <%-- ${doc1} is empty --%>
Simlar using <a href/>
works good:
<c:set value='<a href="/fullurl/x">here</a>' var='doc1'/>
<spring:message code="doc.link" arguments="${doc1}"/>
messages.properties:
doc.link = Doc is {0}
EDIT I need to work exactly something like that:
<c:set value='<a href="<c:url value="/x"/>">here</a>' var='doc1'/>
Upvotes: 6
Views: 11559
Reputation: 597106
<c:url>
has an option to set the result to a variable, rather than outputting it. Just set the var
attribute.
<c:url value="..." var="doc1" />
Upvotes: 5
Reputation: 1108722
Put it in the tag body:
<c:set var="doc1"><a href="<c:url value="/x" />">here</a></c:set>
<spring:message code="doc.link" arguments="${doc1}"/>
Or if you want XML well-formness:
<c:url var="url" value="/x" />
<c:set var="doc1"><a href="${url}">here</a></c:set>
<spring:message code="doc.link" arguments="${doc1}"/>
Upvotes: 14
Reputation: 62583
You can do this:
<c:url var="myURL" value="/x" />
<spring:message code="doc.link" arguments="${myURL}" />
Because your message is doc.link = Doc is {0}
where in the {0}
appears at the end of the message, you can simply change the message to doc.link = Doc is
and do as follows:
<spring:message code="doc.link" /><a href="<c:url value="/x"/>">here</a>
That will do exactly what you want to do!
Upvotes: 4