Announcement Announcement Module
Collapse
No announcement yet.
LocaleChangeInterceptor - probably easy to solve for the right person Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LocaleChangeInterceptor - probably easy to solve for the right person

    Hello fellow Spring programmers.

    I just took the first step into the area of internationalization, where i will be preparing a Spring MVC application for multi-language use. I googled and read a few examples (like this one: http://viralpatel.net/blogs/spring-3...orial-example/) and it seems pretty straightforward. I used the exact same setup from this example and the code from the fix referenced in it. I have seen this same setup in a number of posts on different forums.

    The one thing i don't fully understand is this: I have a controller method with a mapping that looks like this:
    Code:
    @RequestMapping(value = "/placeDetails.htm", method = RequestMethod.GET) public String showPlaceDetails(Model model, @RequestParam(value = "placeId", required = true) int placeId, Locale locale) {
    It would catch a request like this one: www.me.com/placeDetails.htm?placeId=123.

    The href that i add to the "change language" menu item says href="?lang=en". As far as i can see, i end up with the URL www.me.com/placeDetails.htm?lang=en (i see this when i hover over the menu item). The method's request mapping above will not recognize this and i get an error message from Tomcat saying "The request sent by the client was syntactically incorrect ().". My controller knows of no call to www.me.com/placeDetails.htm with a parameter called lang.

    It was (and still is) my assumption that i should not have to add another method with a request mapping that includes the lang parameter. I assumed the LocaleChangeInterceptor would intercept this call and handle it.

    So my question is: am i making the right assumption and if i am not, how is the interceptor supposed to work when the controller method has other parameters. If i am making the right assumption - any ideas why this is not working.

  • #2
    Seriously, is there not a single person out there who knows anything about this? After googling on it for hours, i'm getting convinced i'm expecting something that the Interceptor will not handle. Does this mean i have to rig the change language url parameters to include not only the "?lang=en" part, but also all other parameters needed for the controller to recognize the call in its request mapping?

    I mean in this particular example, i'd have to add "?placeId=123&?lang=en" to the href of the change language menu item in my JSP.

    If that's the way to do it, there is no way to have a generic header part used in multiple JSP pages with the change language menu item in it. I'm hoping there's a more elegant solution than that.

    Comment


    • #3
      There isn't (unless you create a no-op url/which basically re-renders the current page)... You basically re-issue the previous request with an additional parameter to change the language.

      Comment


      • #4
        Thank you, Marten. Not the news i wanted, but at least now i can move on. I suppose i was expecting too much of Spring this time. You get spoiled.

        Comment

        Working...
        X