0

I currently use smartGwt (version 2.5) inside an other framework (Broadleaf).

When i set the locale to french :

Date fields are well formated (DD/MM/YYYY) and the calendar is translated in french but when i change the date and save the form a popup appear with the error message :"Doit être une date" (Must be a date in english). The validator expect a date with MM/DD/YYYY format.

Link to the class used by the framework to create the date field : https://github.com/BroadleafCommerce/BroadleafCommerce/blob/BroadleafCommerce-2.2.x/admin/broadleaf-open-admin-platform/src/main/java/org/broadleafcommerce/openadmin/client/datasource/dynamic/module/BasicClientEntityModule.java

I found a post with same problem (forums.smartclient.com/showthread.php?t=19847) but there is no answer.

Please, let me know how to solve this problem

EDIT :

What i have tried :

@Override
public void onModuleLoad() {

DateUtil.setShortDateDisplayFormat(DateDisplayFormat.TOEUROPEANSHORTDATE);      
    DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {  
        @Override
        public String format(Date date) {
            if(date == null)
            {
               return null;
            }
            else{
                final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("DD/MM/YYYY");
                return dateFormatter.format(date);
            }
        }
    });

Because the code below is not allowed :

    DateUtil.setShortDateDisplayFormatter(DateUtil.TOEUROPEANSHORTDATE);    

I put my code during the application initialization but the problem still present :-(

Screenshot : http://www.hostingpics.net/viewer.php?id=989088date.png

Do you have an other idea?

Denis Cucchietti
  • 201
  • 6
  • 16

2 Answers2

0

Set date formatter of the field to DateDisplayFormat.TOEUROPEANSHORTDATE.

dateItem.setDateFormatter(DateDisplayFormat.TOEUROPEANSHORTDATE);

Also check display seconds in DateTimeItem (SmartGWT) to find another way to set a custom formatted date string when dateItem.useTextField is true.

As the forum thread indicates, its also possible to set default date/datetime format for the application using methods of com.smartgwt.client.util.DateUtil, which should be used only once, during application initialization (e.g.- EntryPoint).

DateUtil.setShortDateDisplayFormatter(DateUtil.TOEUROPEANSHORTDATE);
Community
  • 1
  • 1
Sithsu
  • 2,209
  • 2
  • 21
  • 28
  • Thanks for your answer Sithsu, however i can't set date formatter on the field because the field is built by the framework : field = new DataSourceDateTimeField(propertyName, friendlyName); My only option is to use DateUtil during application initialization, but i have tried several things without success. Do you have an example on how to use DateUtil during application initialization (i'm not very familiar with gwt)? Thank you very much! – Denis Cucchietti Jul 30 '13 at 18:25
  • @Barnouille Specified field in your link that is built by the framework is a data source field. Do you have access to actual form field, or is there some way to gain access to your form fields through framework API? Will need to check what is allowed by methods in the framework. Updated answer on DateUtil. Will have to find a place that is executed during application init to use it. – Sithsu Jul 30 '13 at 18:44
  • Thanks. Unfortunnaly i've no access to the form field, everything is managed by the framework :-/. I will try tomorrow to place the DateUtil during application init and report back ;-). Thanks again for your help! – Denis Cucchietti Jul 30 '13 at 19:06
  • Hi SithSu, i have edited my post to give you more details. Because the problem still present. Thanks for your help – Denis Cucchietti Jul 31 '13 at 12:38
  • @Barnouille May be framework is using DateUtil internally or something. Best option would be to check framework API/documentation and see if there's a way to set date format. Try to get hold of framework developers (mail/forum/site/call/etc.) if possible. Another thing to do is search framework classes/API documentation for dateitem/dateformatter or similar. – Sithsu Jul 31 '13 at 17:44
  • Thanks for your help Sithsu, i will try to have some help with the framework team. – Denis Cucchietti Jul 31 '13 at 19:17
0

Problem solved !

You have to use the code below during application initialization :

private static final String DATE_FORMAT = "dd/MM/yyyy HH:mm";

public void onModuleLoad() {    
        DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() {      
            @Override
            public String format(Date date) {
                if(date != null)
                {
                    final DateTimeFormat dateFormatter = DateTimeFormat.getFormat(DATE_FORMAT);
                    return dateFormatter.format(date);
                }
                return null;
            }
        });

        DateUtil.setDateParser(new DateParser()
          {
             public Date parse(String dateString)
             {
                 try{
                     if(dateString != null){
                         final DateTimeFormat format = DateTimeFormat.getFormat(DATE_FORMAT);
                         return format.parse(dateString);
                     }
                 }catch(Exception e){
                     e.printStackTrace();
                 }
                 return null;
             }
          });
}
Denis Cucchietti
  • 201
  • 6
  • 16