Results 1 to 3 of 3

Thread: Spring Javascript Locale

  1. #1
    Join Date
    Feb 2010
    Posts
    22

    Default Spring Javascript Locale

    Hi *,

    I have a locale problem with spring javascript and the DateTextBox decoration. This is my JSP code:

    HTML Code:
    <label for="startDate"><fmt:message key="options-top.searchoptions.from" /></label><br/>
    <form:input path="startDate" id="startDate" />
    <a href="javascript:void(0);" onclick="dijit.byId('startDate').focus();">
    <img src="<c:url value="/images/calendar_icon.gif" />" alt="Calendar" />
    </a>
    <script type="text/javascript">
    Spring.addDecoration(new Spring.ElementDecoration({
    	elementId : 'startDate', 
    	widgetType : 'dijit.form.DateTextBox', 
    	widgetAttrs : {
    		required : true,
    		datePattern : 'yyyy-MM-dd',
    		staticDisplay: true
    	}
    }));
    </script>
    My problem: The Calendar Popup is always rendered in German (I suppose that's because I use a German Firefox), regardless of the page's locale.

    I tried the following to set DOJO's locale, but it does not work:

    Code:
     	<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
    		<property name="requestContextAttribute" value="rc" />
    	</bean>
    HTML Code:
    	<script type="text/javascript">
    	var djConfig={
    		locale: '${rc.locale.language}'
    	};
    	</script>
    	<script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />" ></script>

  2. #2
    Join Date
    Feb 2010
    Posts
    22

    Default

    OK I got it now ....

    My approach was almost correct, I just forgot to set parseOnLoad=true:

    HTML Code:
    	<script type="text/javascript">
    	var djConfig={
    		locale: '${rc.locale.language}',
    		parseOnLoad: true
    	};
    	</script>
    	<script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />" ></script>

    I think that for convenience spring-javascript should be able to do this automatically. Should I file a request for enhancement ?

  3. #3
    Join Date
    Feb 2010
    Posts
    22

    Default

    Yes, I know it is possible to change the browser's preferred locale. But unfortunately it's impossible to query this preference from Javascript (or at least there is no possibility that I know of). This is why I need to include the request's locale as javascript variable "djConfig" in the JSP page, as shown above.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •