Ron DeSantis
Ron DeSantis

Reputation: 935

How do I get my legacy JSP backend to recognize UK-style dates from the frontend?

I am maintaining a very old Java Spring MVC JSP portal application with old JQuery on the front-end. To date it has only operated in the US. Now I am adapting it for UK users. So far, I have handled all the currency references and all the date and time outputs; that is, pages and export files are now formatting dates and times correctly for the UK. The problem is with date and time inputs.

Dates and times are input on the frontend using old JQuery datepicker and datetimepicker. In addition to selecting from the calendar dropdown, the user can type dates and times directly into the text box of the picker. The frontend has elaborate logic to allow various abbreviated and alternate formats to be entered. Once entered, the input is validated and then converted to a standard format in the text box. All this logic is now working correctly for the UK and the pickers work perfectly on the frontend. The datetimepicker is effectively configured like this:

$(this.formEl + ' .timestamp-picker').datetimepicker({
    showOn: 'button',
    format: 'dd/mm/yy HH:mm',
    dateFormat: 'dd/mm/yy',
    timeFormat: 'HH:mm',
    buttonImage: '../src/images/calendar.gif',
    controlType: 'select',
    buttonImageOnly: true,
    constrainInput: false
});

The problem is when I submit a form with one of these pickers. The backend interprets the dates as though they were in en_US format, not en_GB. For example, if I enter 2/1/2020 on the frontend, the backend interprets this as though it were 1 February, not 2 January.

The backend specifies locale in myapp-servlet.xml as follows:

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />
</bean>

I tried changing the value to "en_GB" but that made no difference in the behavior. Should it have?

I can't find frontend or backend code that intercepts requests from frontend to backend and interprets dates. Does a Spring MVC JSP application typically have code like that? If so, where would I find it? In general, how do I configure the JSP backend for the date and time formats expected from the frontend?

Upvotes: 1

Views: 24

Answers (0)

Related Questions