Skip to Content

More than one interceptor of one type

Hi Experts,

Platform already has introduced InitDefaultsInterceptor for type. Now I need to populate one more property for type with default value, and going to introduce second InitDefaultsInterceptor for it.

Just want to confirm, that it is not bad practice to have two InitDefault interceptors. Or it is better to somehow extend(maybe even replace) existing one?

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jun 11, 2018 at 10:15 AM

    It's not bad practice, in fact there is an example of using multiple InitDefaults interceptors in the cms2 extension. There is an InitDefaults interceptor on the CMSRelation type and then separate ones on the sub types ContentSlotForPage and ContentSlotForTemplate

    If you need your new interceptor to fire before other ones then there is an order attribute, or use the replacedInterceptors to completely replace the existing one.

    https://help.hybris.com/6.7.0/hcd/8bfbf43e8669101480d0f060d79b1baa.html#interceptors-registeraninterceptor

    Also as has pointed out you can just override the default bean with your one but I wouldn't go as far as saying that this is better, it's just a different way of achieving the same result.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.