0

Is there any way to add the custom controller rendering in a placeholder in SXA?

Whenever I add the controller rendering inside the placeholder I keep getting errors for example Object not set to reference or something like that? I have the code for this specific controller rendering and it does work on other components but when I try to apply it on this new component inside placeholder it just does not work.

Any tips on why is this happening?

2
  • My guess is that you don't have defensive code in your controller to cope with a null/not set datasource item and its erroring before you are able to add a datasource to the rendering. Can you share some code or more detail around your issue?
    – Richard Seal
    Commented Feb 17, 2022 at 19:39
  • When you say, when you put this on another component it works but when you put in this placeholder it does not work, can you elaborate that part? Simplest thing for you would be to check logs and you will see, your controller might be expecting something which is null and hence its breaking, let me know with more details of what you mean when you say it works on other component? Commented Apr 8 at 8:22

1 Answer 1

0

I don't think this is the issue of the placeholder. The placeholder will work the same for all kinds of renderings.

It is important that the controller inherit from StandardController or from a class which inherit from StandardController.

The issues of Object not set to reference, may come if object is null and to handle this you need to add null reference check in your code.

Last, if your controller is not creating any error, then you have to add a static HTML in your view to check if the error is coming by adding any unexpected HTML code? If yes, then you need to correct this.

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.