Spring locale messages don't work only within spring:form tag

旧时模样 提交于 2019-12-25 02:09:06

问题


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=""/>

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'/>

The value is as I should be.

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.

I'm sure there must be a way to do this with spring mvc.


回答1:


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=""/>


来源:https://stackoverflow.com/questions/13251010/spring-locale-messages-dont-work-only-within-springform-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!