Spring语言环境消息仅在spring:form标记中不起作用 [英] Spring locale messages don't work only within spring:form tag
问题描述
您好,我有一个表单输入按钮,如下所示:
Hello I have a form input button as follows :
<form:input path="creationUsr.lastName" type="text" name="creationUsr.lastName" id="creationUsr.lastName" class="login-text" placeholder="<spring:message code='tile.form.lastName'/>" value=""/>
这是我的spring上下文语言环境设置:
Here is my spring context locale setting :
<mvc:interceptors>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
</mvc:interceptors>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
如果我将其放在表单标签之外:
If I put this out of form tag :
<spring:message code='tile.form.lastName'/>
值是我应该的.
我有办法解决这个问题,但这有点丑陋.我可以不使用spring和常规的<input type="text" name="lastname">
而不是<form:input
..恢复到常规形式,然后将表单序列化为json并使用javascript做文章.
I have a way around this but it's kind of ugly. I could revert to normal forms without using spring and regular <input type="text" name="lastname">
instead of <form:input
.. and then serialize form to json and do a post with javascript.
我敢肯定,必须有一种使用Spring MVC做到这一点的方法.
I'm sure there must be a way to do this with spring mvc.
推荐答案
您不能在另一个JSP标记的属性内使用JSP标记.要执行您想要的操作,请将消息保存在page-scope属性中,然后使用EL将消息传递到输入标签:
You can't use a JSP tag inside an attribute of another JSP tag. To do what you want, save the message in a page-scope attribute, and use the EL to pass the message to the input tag:
<spring:message code='tile.form.lastName' var="lastNameMessage"/>
<form:input path="creationUsr.lastName"
type="text"
name="creationUsr.lastName"
id="creationUsr.lastName"
class="login-text"
placeholder="${lastNameMessage}"
value=""/>
这篇关于Spring语言环境消息仅在spring:form标记中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!