0

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 :-)

  • Do you have any exception if you pass a different date? – Roman C Aug 24 '23 at 07:56
  • Hi Roman, I haven't any Exceptions, and I cannot debug, so I set '' and in struts config, when I select "en" or "de" and I set date in page with datepicker after I submit form to search data I see in Wildfly console "Unexpected Exception caught setting 'dateOrderMin' on 'class i....Action: Error setting expression 'dateOrderMin' with value ['24/08/2023' " and I lose control of application – Giuseppe Coniglio Aug 25 '23 at 10:33
  • I solved by changing the type of variable from Date to String in 'myDate', associating this variable to the Jquery struts2 datepicker: When select date in page and submit form the Action when reading the String, e.g. '22/08/2023' formats it as Date with Simpledateformat dd/MM/yyyy and passes it to the data search query in the DB. By changing any language from the frontend and setting the Locale the data search always keeps working and it doesn't crack anymore – Giuseppe Coniglio Aug 25 '23 at 11:04
  • It doesn't work, 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 : – Giuseppe Coniglio Aug 30 '23 at 14:35

0 Answers0