cancel
Showing results for 
Search instead for 
Did you mean: 

Change Date format in cockpit editor area

Former Member
0 Kudos

Hi all,

I want to change the date format from a Date field in my EditorArea.

At the moment it looks this way:


Editor area xml looks the following way:

 <?xml version="1.0" encoding="UTF-8"?>
 <editor>
     <group qualifier="General" visible="true" initially-opened="true">
         ...
         <property qualifier="MyModel.openingSchedule.openingDays" visible="true"  />
         ...
     </group>
 </editor>

The opening days is a list with several days.

And my base Editor for openingDays (resp. WeekdayOpeningDay) looks so:

 <?xml version="1.0" encoding="UTF-8"?>
 <base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="base.xsd">
     <label>
         <property qualifier="WeekdayOpeningDay.dayOfWeek"/>
         <property qualifier="WeekdayOpeningDay.openingTime" />
         <property qualifier="WeekdayOpeningDay.closingTime" />
     </label>
 </base>

OpeningTime and closingTime are Dates and dayOfWeek is an Enum. I use this base.xml to show the details of the openingDay and not just the pk.

I would like to change the Date format in the following way: MONDAY - 08:00:00 - 18:00:00 --> Only the Enum Value and the times.

In addition to that I would like to have an editor for the times, so that I can change them.


Do you have any idea how to change the display of the date?

Accepted Solutions (1)

Accepted Solutions (1)

cieslo
Active Participant
0 Kudos

Hi Theresa,

you could use a LabelProvider class for this scenario. In my sample code I used admincockpit to see the changes and base_WeekdayOpeningDay.xml (in admincockpit the "Opening schedule" generic item). In your base_openingDay.xml you should have something like this (this defines that the labels will be loaded through spring bean):

<?xml version="1.0" encoding="UTF-8"?>
<base xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="base.xsd">
    <label spring-bean="openingDayLabelProvider"/>
</base>

Next thing is to define a bean in your extension resources/admincockpit/admincockpit-spring-services.xml:

...
<bean id="openingDayLabelProvider" class="de.hybris.platform.admincockpit.services.label.impl.OpeningDayLabelProvider" scope="tenant"/>
...

And the last thing is to write your own LabelProvider class - something similar to this:

package de.hybris.platform.admincockpit.services.label.impl;
import de.hybris.platform.cockpit.services.label.AbstractModelLabelProvider;
import de.hybris.platform.storelocator.model.WeekdayOpeningDayModel;
import java.text.DateFormat;
import java.util.Locale;
public class OpeningDayLabelProvider extends AbstractModelLabelProvider<WeekdayOpeningDayModel>
{
    private static final String SEP = " - ";
    @Override
    protected String getItemLabel(final WeekdayOpeningDayModel item)
    {
        final StringBuffer label = new StringBuffer();
        final String dayOfWeek = item.getDayOfWeek().toString();
        label.append(dayOfWeek);
        final Locale locale = Locale.GERMAN;
        final DateFormat df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
        final String openingTime = df.format(item.getOpeningTime());
        label.append(SEP);
        label.append(openingTime);
        label.append(SEP);
        final String closingTime = df.format(item.getClosingTime());
        label.append(closingTime);
        return label.toString();
    }
    @Override
    protected String getItemLabel(final WeekdayOpeningDayModel item, final String languageIso)
    {
        return getItemLabel(item);
    }
    @Override
    protected String getItemDescription(final WeekdayOpeningDayModel item)
    {
        return getItemLabel(item);
    }
    @Override
    protected String getItemDescription(final WeekdayOpeningDayModel item, final String languageIso)
    {
        return getItemLabel(item);
    }
    @Override
    protected String getIconPath(final WeekdayOpeningDayModel item)
    {
        return "";
    }
    @Override
    protected String getIconPath(final WeekdayOpeningDayModel item, final String languageIso)
    {
        return "";
    }
}

Hope this helps.

Former Member
0 Kudos

Hi Marcin,

thanks for the answer. This helps me very much. The view for the Opening Hours is great.

Do you know if there is a possibility to edit a specific field in the label? E.g. I want to change MONDAY - 8:00:00 AM - 4:00:00 PM to MONDAY - 9:00:00 AM - 4:00:00 PM.

cieslo
Active Participant
0 Kudos

Hi Theresa,

if you would like to change tha label without modyfing the data (for example you have opening time = 9:00:00 and you want tha label to display 10:00:00 you should do this in LabelProvider class in getItemLabel method). If you would like to change the data on record then you should use "Details" icon in cockpit () and modify the field in new "Edit" view.

Former Member
0 Kudos

Hi Marcin,

I don't have this pencil icon for my opening day.. But I added my own create wizard for the opening days and there I can create and change the details for my opening day.

Thanks for your help!

Answers (0)