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

Custom Preview Resolution Strategy


Following the article, I was trying to introduce some custom Preview Resolution Strategy.

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

 <bean id="nothingChangingStringPreviewResolutionStrategy" class=""/>
 <alias name="myObjectPreviewService" alias="objectPreviewService"/>
 <bean id="myObjectPreviewService" parent="backofficeObjectPreviewService">
     <property name="urlResolutionStrategies">
         <list merge="true" value-type="">
             <ref bean="nothingChangingStringPreviewResolutionStrategy"/>

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="">
     <property name="objectPreviewService" ref="objectPreviewService"/>

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