Skip to content

Add <spring:argument> subtag for <spring:message> [SPR-9678] #14312

Closed
@spring-projects-issues

Description

@spring-projects-issues

Nick Williams opened SPR-9678 and commented

The JSTL tag <c:url> can contain parameter placeholders in its value, and nested <c:param> tags supply values for those placeholders. Likewise the spring:url tag can contain parameter placeholders in its value, and nested spring:param tags supply values for those placeholders.

However, things differ for i18n. fmt:message, like <c:url>, uses nested fmt:param tags to replace message parameters. However, spring:message does not. It instead has a flat attribute that expects a comma-(by default)-separated LIST of arguments, and contains an optional attribute for specifying a different delimiter.

This is an onerous way to use this feature. If I have a parameter in a message that can contain any number of typical delimiters (for example, I'm displaying an error message), I have to go to extreme lengths to display this properly without worrying about improper splitting:

<spring:message code="error.logged.message" argumentSeparator=";||?||;" arguments="${exception.localizedMessage}" />

This would make much more sense, and match not only the JSTL but also other Spring tags (like spring:url):

<spring:message code="error.logged.message"><spring:param value="${exception.localizedMessage}" /></spring:message>

I believe this is a much-needed improvement for this tag, and the existing arguments and argumentSeparator attributes could be left in place for backwards compatibility.

Would love to see this in 3.2.x... :-)


Affects: 3.0.1, 3.0.7, 3.1.1, 3.1.2

Referenced from: commits 66cfe9f, f9b17a7

1 votes, 5 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions