cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Preview Resolution Strategy

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?

Accepted Solutions (1)

Accepted Solutions (1)

former_member632755
Active Contributor
0 Kudos

After a short investigation I see a few dependencies and possibilies:

  1. If the strategy should be changed only for the part of the application defined in the your module (which has a separate application context being a child context of the web context of backoffice) you can proceede as I described before

  2. If you want all backoffice modules to use your new beans you have to extend the parent context. To do so you can follow instructions available here: https://wiki.hybris.com/display/release5/Cockpit+Data+Integration+Layer+of+the+Next+Generation+Cockp... Basicly you have to declare an "extender" that will register your new beans in the appropriate bean of parent web context (PostConstruct). For clear solution PreDestroy should be also implemented to "unregister" the beans in case of context's shutdown.

Best, Wojtek

former_member632755
Active Contributor
0 Kudos

In case you needed more information on the contexts try reading https://wiki.hybris.com/display/release5/Widget+Application+Context

0 Kudos

Thanks, Wojtek. So, now there are two options if we need variant 2:

  1. Create Extender and get or set private variable with no accessors|mutators either in DefaultPreviewListCellRenderer, or in DefaultObjectPreviewService.

  2. Extend and redeclare DefaultPreviewListCellRenderer in order to set objectPreviewService property via reflection or rewrite it completely to do it.

Answers (2)

Answers (2)

0 Kudos

Hi Wojtek,

I did tried to customize by overrididng and adding all as a list again, but it is not showing up in lower environments. In local, it is working fine. But not in Lower environments. Can you please help me out on idenitfying the root cause on why it is not shwoing up in environmnets.

former_member632755
Active Contributor
0 Kudos

Hi,

as far as I understand your strategy should be used when a String is passed (ie. its generic type is ). If you take a look at StringToPreviewResolutionStrategy you will find that it aslo has the same generic type - . Becaouse you are specifying list merge="true" you will have your strategy appended to the resolution queue. In this case the original strategy will be used (StringToPreviewResolutionStrategy) since the objectPreviewService stops the lookup after first successful application of a strategy (see the canResolve(Object) method).

In my opinion the easiest way would be to redeclare the list and point to all required strategies explicitly (without merge) in the order you want them to be applied.

Regards, Wojtek

0 Kudos

As I said, the defaultPreviewListCellRenderer keeps using the old objectPreviewService, as there were only 2 strategies in the list: the ootb ones, while mine objectPreviewService has three or one, depending on whether I use merge or not. Apparently, the way to add a strategy in the list works for the OOTB media strategy because it is in the same extension, but does not for our custom backoffice extension.