[MAGNOLIA-3304] Renderer doesnt restore the model attribute after rendering is done Created: 23/Sep/10  Updated: 01/Dec/10  Resolved: 15/Nov/10

Status: Closed
Project: Magnolia
Component/s: templating
Affects Version/s: 4.3.6
Fix Version/s: 4.4

Type: Bug Priority: Major
Reporter: Tobias Mattsson Assignee: Tobias Mattsson
Resolution: Fixed Votes: 0
Labels: model, rendering, templating
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
relation
is related to MAGNOLIA-3316 Support execution of paragraph models... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

Before rendering AbstractRenderer.saveContextState() takes a snapshot of the values it will change, but this doesnt include "model". Then AbstractRenderer.setupContext() sets "model", afterwards the snapshot is used to restore the attributes but this doesnt include "model".

Reported on the user list by Stein Kvarud <stein.kvarud@iterate.no>

Original description:

Hi.

I discovered some sideeffects with the way magnolia does paragraph
loading that to me seems like a bug.
When including a paragraph the model reference are set to the model of
the paragraph. Next when the rendering of the paragraph is done I
expected the model reference to be set back to the template rendering
model, but the reference stays at the model class of the final
paragraph.
This can cause some strange sideeffects because the reference to the
model in the template are influenced by the paragraphs added to the
page.

I have created a small sample to illustrate the problem.

Creating two custom RenderingModels for a template and a paragraph

public class MyTemplateRenderingModel extends
RenderingModelImpl<RenderableDefinition> {

public MyTemplateRenderingModel(Content content,
RenderableDefinition definition, RenderingModel<?> parent)

{ super(content, definition, parent); }

public String getClassName(){ return this.getClass().getName(); }

}

public class MyParagraphRenderingModel extends
RenderingModelImpl<RenderableDefinition> {

public MyParagraphRenderingModel(Content content,
RenderableDefinition definition, RenderingModel<?> parent) { super(content, definition, parent); }

public String getClassName()

{ return this.getClass().getName(); }

}

Then adding two smal jsp files

The template:

Model value before loading paragraphs = ${model.className}

<cms:contentNodeIterator contentNodeCollectionName="testCollection">
<cms:includeTemplate />
</cms:contentNodeIterator>
<cms:newBar contentNodeCollectionName="testCollection"
paragraph="testParagraph" newLabel="New test paragraph" />

Model value after loading paragraphs = ${model.className}

The paragraph:

<p>
Model class name inside paragraph = ${model.className}
</p>

Then I add a modelClass for the paragraph and the template in the
magnoli configuration.

Before adding any paragraphs to the template it displays

Model value before loading paragraphs = MyTemplateRenderingModel
Model value after loading paragraphs = MyTemplateRenderingModel

I then add one (or more) paragraphs
Model value before loading paragraphs = MyTemplateRenderingModel
Model class name inside paragraph = MyParagraphRenderingModel
Model value after loading paragraphs = MyParagraphRenderingModel

As the example illustrates the final output from model.className
refers to the paragraph and not the template.

Do I need to add some tag to the jsp to avoid this sideeffect or is this a bug?

Regards
Stein



 Comments   
Comment by Tobias Mattsson [ 01/Dec/10 ]

The fix was in r39093
http://svn.magnolia-cms.com/view/community/magnolia/branches/magnolia-4.4/magnolia-module-templating/src/main/java/info/magnolia/module/templating/AbstractRenderer.java?annotate=39093#l119

Comment by Jan Haderka [ 01/Dec/10 ]

changes for MAGNOLIA-3316 fix this issue as well.

Generated at Mon Feb 12 03:45:12 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.