I have the following form.
<form id="langForm" action="" method="get">
<select name="lang" id="lang" class="styled" onchange="this.form.submit();">
<option value="pl" ${param.lang == 'pl' ? 'selected' : ''} >PL</option>
<option value="en" ${param.lang == 'en' ? 'selected' : ''} >EN</option>
</select>
</form>
Spring MVC sets the language parameter and takes care about i18n/l10n. I would like to change the ${param.lang} to let it obtain the current user language from session by Spring MVC, because the lang parameter is not necessarily present in every request. How can I achieve this?
Add the fallowing in your xml configuration:
Replace you code by:
With this configuration the locale selected wil be save in cookies browser.
don’t forget namespaces at the begin of file in tag :
xmlns:mvc=”http://www.springframework.org/schema/mvc”
and
xsi:schemaLocation=”http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
tutorial here