Skip to Content
1
Jul 29, 2014 at 09:33 AM

Custom Preview Resolution Strategy

339 Views

Following the article, I was trying to introduce some custom Preview Resolution Strategy. https://wiki.hybris.com/display/release5/Thumbnails+in+the+Reference+Editors

The configuration strings in customermodule-backoffice-spring.xml are:

 <bean id="nothingChangingStringPreviewResolutionStrategy" class="com.company.customer.module.services.media.impl.NothingChangingStringPreviewResolutionStrategy"/>
 <alias name="myObjectPreviewService" alias="objectPreviewService"/>
 <bean id="myObjectPreviewService" parent="backofficeObjectPreviewService">
     <property name="urlResolutionStrategies">
         <list merge="true" value-type="com.hybris.cockpitng.services.media.PreviewResolutionStrategy">
             <ref bean="nothingChangingStringPreviewResolutionStrategy"/>
         </list>
     </property>
 </bean>

This way, it creates new objectPreviewService with my strategy, but keeps using the old instance(backofficeObjectPreviewService) in previewListCellRenderer. So I redeclared previewListCellRenderer like this to get the new objectPreviewService autowired:

 <alias name="customPreviewListCellRenderer" alias="previewListCellRenderer"/>
 <bean id="customPreviewListCellRenderer" parent="defaultPreviewListCellRenderer"/>

In this case, the objectPreviewService attribute is null when ListCellRenderer is called. So it wasn't autowired, and there was no errors. And it is impossible to inject it traditionally, because there is no setter method.

It worked when I wrote a custom ListViewRenderer, doing exactly the same plus setObjectPreviewService(), and injected objectPreviewService old-fashioned way:

 <alias name="customPreviewListCellRenderer" alias="previewListCellRenderer"/>
 <bean id="customPreviewListCellRenderer" class="com.company.customer.module.widgets.listview.impl.CustomPreviewListCellRenderer">
     <property name="objectPreviewService" ref="objectPreviewService"/>
 </bean>

Is there a simpler way to redeclare existing or add new preview resolution strategy?