cancel
Showing results for 
Search instead for 
Did you mean: 

Defining date format for Extended Multi Reference Editor

Former Member
0 Kudos
686

Hi Experts,

we have to display some date attributes for entities in a ExtendedMultiReferenceEditor (https://help.hybris.com/6.1.0/hcd/8bab997f86691014852cfbeabd21a5c8.html).

Things work flawlessly except we weren't able to find out how to configure the date format. In fact we would only need the date (without time or time zone) both for output as well as input.

This requirement can be done easy be fulfilled for the default date editor (see https://help.hybris.com/6.1.0/hcd/8baaee208669101492bbcf156de5928f.html), but couldn't find anything for extended multi reference editor.

Thanks, Best Regards, Norbert

Accepted Solutions (1)

Accepted Solutions (1)

former_member638520
Contributor
0 Kudos

Hi Norbert,

In order to change displaying value, you have two options:

Changing base configuration for java.util.Date and creating your own LabelProvider:

cockpit-config.xml:

 context type="java.util.Date" component="base">
         <y:base xmlns:y="http://www.hybris.com/cockpit/config/hybris">
             <y:labels beanId="dateLabelProvider"/>
         </y:base>
     </context>

spring-config.xml

 import com.hybris.cockpitng.labels.LabelProvider;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
 public class DateLabelProvider implements LabelProvider<Date>
 {
     @Override
     public String getLabel(final Date object)
     {
         return new SimpleDateFormat("MM-dd-yyyy").format(object);
     }
 
     @Override
     public String getDescription(final Date object)
     {
         return "";
     }
 
     @Override
     public String getIconPath(final Date object)
     {
         return "";
     }
 }


The second option is providing your own DateListCellRenderer:

 public class DateListCellRenderer extends AbstractWidgetComponentRenderer<Listcell, ListColumn, Object>
 {
     private WidgetRenderingUtils widgetRenderingUtils;
 
     @Override
     public void render(Listcell listcell, ListColumn configuration, Object o, DataType dataType, WidgetInstanceManager widgetInstanceManager) {
         final String qualifier = configuration.getQualifier();
         final QualifierLabel label = getWidgetRenderingUtils().getAttributeLabel(o, dataType, qualifier);
         final String formattedDate = ""; // do sth with label
         listcell.setLabel(formattedDate);
     }
 
     public WidgetRenderingUtils getWidgetRenderingUtils()
     {
         return widgetRenderingUtils;
     }
 
     @Required
     public void setWidgetRenderingUtils(final WidgetRenderingUtils widgetRenderingUtils)
     {
         this.widgetRenderingUtils = widgetRenderingUtils;
     }
 }


spring-config.xml

     <bean id="dateListCellRenderer" class="com.hybris.training.renderer.DateListCellRenderer" >
         <property name="widgetRenderingUtils" ref="widgetRenderingUtils"/>
     </bean>

cockpit-config.xml:

  <list-view:column qualifier="startTime" spring-bean="dateListCellRenderer"/>



Unfortunately, AFAIK it's not possible to change (configure) dateEditor for extendedMultiReferenceEditor

Regards,

Łukasz

Former Member
0 Kudos

Hi Lukasz,

thank you for your detailled response! Changing label definitely helps, yet it would be great to also be able to configure the editor.

Best Regards, Norbert

former_member638520
Contributor
0 Kudos

You're welcome:)

Answers (0)