I have a web app with Struts 2.5.30 and struts2-jquery-plugin 4.0.3 , I'm using datepicker with displayFormat="dd/mm/yy"
and when user change language with a click on flag image the param request_locale
goes home page action to change all labels with internazionalization.
This cause in backend when pass the datepicker value on submit in search form that field arrives incorrect format: example if request_locale
is "it"
and in the datepicker select 01 August in debug I see getter method Tue Aug 01 00:00:00 CEST 2023
and return is SUCCESS
with correct search in page, when select English flag and request_locale
is "en"
the same selection 01 August in the getter is 'Sun Jan 08 00:00:00 CET 2023'
and return INPUT
.
Why this ? In the JSP datapicker is:
<sj:datepicker id="myDate" name="myDate" value="%{myDate}" firstDay="1" displayFormat="dd/mm/yy" />
You can see widget https://ibb.co/M2dSdtm
I tried change language in page with flag images (set Locale with request_locale) , is it possible to keep the Locale only for internationalization (which occurs with request_locale) and use the 'Date' fields that always take the date dd/MM/yyyy from the jsp page with the datepicker? If is not possibile I must change type of my variable Date to String and parse to Date in every Action that perform search in database with date orders filters
Also change type it doesn't work , when return Success and go in page date are wrong, example from 01/08/2023 (1 August) you see 08/01/2023 (8 January)
private String data_min_string;
private Date data_min;
Solution:
Also change type from Date to String the problem occours ever. So I must modify every file 'datepicker*'.js (datepicker-uk.js, etc... and 'jquery-ui.min.js', setting -> dateFormat:"dd/mm/yy") in library 'struts2-jquery-plugin-4.0.3.jar'
In jsp no value :
<sj:datepicker id="data_min_string" name="data_min_string" **value**="" firstDay="1" **displayFormat**="dd/mm/yy" />
Furthermore I must set again property before return Success:
public String search() {
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date startFilterDate = null;
if (getData_min_string() != null && !getData_min_string().isEmpty()) {
startFilterDate = new SimpleDateFormat("dd/MM/yyyy").parse(getData_min_string());
setData_min(startFilterDate); // this is field to search in Database
setData_min_string(formatter.format(startFilterDate)); // this field is binding with datepicker by name="data_min_string"
}
Have a nice day :-)