Coldbox Renderer.RenderLayout() Overwrites Event's Current View
Description
Calling `renderLayout()` within a model overwrites the current view in the handler.
To recreate the issue:
1. Create a basic REST API app (the Ortus template is fine) 2. Create a handler in your app called /test/ which extends coldbox.system.restHandler. 3. Add the following code to your handler:
4. Create a new model called 'myService' and make sure to inject it into your handler. Use the following example for your 'myService' model code:
5. Now run your event, and you will see that when your handler dumps: event.getCurrentView() the first time, it will be blank as expected. However, the second instance after the renderer has performed its operation in the service, you will see it output `test/index` (or whatever you named your handler and the current action).
It looks like when the renderer renders a layout, it has a side effect of overwriting the current event's view. Perhaps there is a scoping issue in the renderer somewhere? Note this doesn't happen if you execute renderer.renderView() in your service. It only happens with renderer.renderLayout().
Hopefully, this information helps, and that it's not terribly difficult to fix.
I recorded a video showing how to replicate the issue:
Please let me know if you need any additional information to help troubleshoot.
David LevinJuly 10, 2021 at 5:29 PM
Yes I believe it still is. I’m out of town until Wed but I will try and reproduce again and if it would be easier, I can record a screencast and post it somewhere if that would help in troubleshooting.
Luis MajanoJuly 9, 2021 at 3:04 PM
is this still an issue? I am having tr5ouble replicating/?
David LevinApril 28, 2021 at 9:34 PM
Another side effect of this issue is that you can’t use renderLayout() in a model that needs to render out a bunch of layouts (say for a bunch of email notifications). The only workaround is to not use an email layout/view combo and instead, hard code the layout into every view.
Here’s an example of how to replicate the issue: Inject the renderer into your model:
Create a method to test the renderer. The idea is that it should write out a list of names using the “Simple” layout and the “email/test” view.
The renderer looks like this (not very exciting I know):
Calling `renderLayout()` within a model overwrites the current view in the handler.
To recreate the issue:
1. Create a basic REST API app (the Ortus template is fine)
2. Create a handler in your app called /test/ which extends coldbox.system.restHandler.
3. Add the following code to your handler:
4. Create a new model called 'myService' and make sure to inject it into your handler. Use the following example for your 'myService' model code:
5. Now run your event, and you will see that when your handler dumps:
event.getCurrentView()
the first time, it will be blank as expected. However, the second instance after the renderer has performed its operation in the service, you will see it output `test/index` (or whatever you named your handler and the current action).It looks like when the renderer renders a layout, it has a side effect of overwriting the current event's view. Perhaps there is a scoping issue in the renderer somewhere? Note this doesn't happen if you execute
renderer.renderView()
in your service. It only happens withrenderer.renderLayout()
.Hopefully, this information helps, and that it's not terribly difficult to fix.