title: Spring internationalization: locale change problem
body: <p>I have a web project with internationalization. It's pretty similar to <a href="http://www.springbyexample.org/examples/basic-webapp-internationalization-jsp-example.html" rel="nofollow">http://www.springbyexample.org/examples/basic-webapp-internationalization-jsp-example.html</a>.
  There are links for switching locales in the decorator. They add lang param to the current url:</p>
  
  <pre><code>&lt;a href="?lang=en"&gt;En&lt;/a&gt; | &lt;a href="?lang=ru"&gt;Ru&lt;/a&gt; &lt;/span&gt;&lt;/td&gt;
  </code></pre>
  
  <p>At first time internationalization worked fine. But then we found a problem with some forms. 
  Form:</p>
  
  <pre><code>&lt;form:form action="${pageContext.request.contextPath}/branch/${branchId}/topic.html" modelAttribute="topicDto" method="POST" 
  onsubmit="this.getAttribute('submitted')"&gt; &lt;!--Block multiple form submissions--&gt;
  &lt;table border="2" width="100%"&gt;
      &lt;tr&gt;
          &lt;td width="30%"&gt;
              &lt;form:label path="topicName"&gt;&lt;spring:message code="label.topic"/&gt;&lt;/form:label&gt;
              &lt;form:input path="topicName"/&gt;
              &lt;form:errors path="topicName"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td height="200"&gt;
              &lt;form:label path="bodyText"&gt;&lt;spring:message code="label.text"/&gt;&lt;/form:label&gt;
              &lt;form:textarea path="bodyText"/&gt;
              &lt;form:errors path="bodyText"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;input type="submit" value="&lt;spring:message code="label.addtopic"/&gt;"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>controller:</p>
  
  <pre><code>/**
   * @see Topic
   */
  @Controller
  public final class TopicController {
  /**
   * Method handles newTopic.html GET request and display page for creation new topic
   *
   * @param branchId {@link org.jtalks.jcommune.model.entity.Branch} id
   * @return {@code ModelAndView} object with "newTopic" view, new {@link TopicDto} and branch id
   */
  @RequestMapping(value = "/branch/{branchId}/topic/create", method = RequestMethod.GET)
  public ModelAndView createPage(@PathVariable("branchId") Long branchId) {
      return new ModelAndView("newTopic")
              .addObject("topicDto", new TopicDto())
              .addObject("branchId", branchId);
  }
  
  /**
   * This method handles POST requests, it will be always activated when the user pressing "Submit topic"
   *
   * @param topicDto the object that provides communication between spring form and controller
   * @param result   {@link BindingResult} object for spring validation
   * @param branchId hold the current branchId
   * @return {@code ModelAndView} object which will be redirect to forum.html
   * @throws org.jtalks.jcommune.service.exceptions.NotFoundException
   *          when branch not found
   */
  @RequestMapping(value = "/branch/{branchId}/topic", method = RequestMethod.POST)
  public ModelAndView create(@Valid @ModelAttribute TopicDto topicDto,
                             BindingResult result,
                             @PathVariable("branchId") Long branchId) throws NotFoundException {
      if (result.hasErrors()) {
          return new ModelAndView("newTopic").addObject("branchId", branchId);
      } else {
          Topic createdTopic = topicService.createTopic(topicDto.getTopicName(), topicDto.getBodyText(),
                  branchId);
          return new ModelAndView("redirect:/branch/" + branchId + "/topic/"
                  + createdTopic.getId() + ".html");
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>If the user post the form with invalid fields it will see validation messages before the fields. If he switch page language at that moment he will see the error:</p>
  
  <pre><code>HTTP Status 405 - Request method 'GET' not supported
  type Status report
  message Request method 'GET' not supported
  description The specified HTTP method is not allowed for the requested resource (Request method     'GET' not supported).
  Apache Tomcat/7.0.11
  </code></pre>
  
  <p>you can check the problem yourself at our development server
  <a href="http://deploy.jtalks.org/jcommune/index.html" rel="nofollow">http://deploy.jtalks.org/jcommune/index.html</a>
  for example at registration page
  <a href="http://deploy.jtalks.org/jcommune/registration.html" rel="nofollow">http://deploy.jtalks.org/jcommune/registration.html</a>
  leave the form blank and submit it. You will see validation messages. than change the language and submit form one more time to see the specified error.</p>
  
  <p>You can find all our sources here <a href="http://fisheye.jtalks.org/" rel="nofollow">http://fisheye.jtalks.org/</a></p>